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

Php - Delimiter must not be alphanumeric or backslash -

c# - How to change the "Applies To" field under folder auditing options programatically (.NET) -

c++ - Ambiguity when using boost::assign::list_of to construct a std::vector -