javascript - Add selected in option using jquery -


i trying have 1 of values in list selected. have hidden field have match values in option of selection. if finds 1 has selected.

this code have.hidden field html code.

   <input type="hidden" id="supp" name="supp" value="<?php echo $_post['suppliers'];?>" /> 

my js:

<script type="text/javascript"> $(document).ready(function() { var addselected = $('#supp').val(); $("#suppliers option[value='" + addselected + "']").attr("selected","selected");  console.log(addselected); });  </script> 

the code above not working.

here's jsfiddle shows better way this: http://jsfiddle.net/atjvv/

you can call .val on <select> itself.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -