using jquery to set value of a select box -
i trying set value of select box using jquery.here's code have:
$(function() { $("#contact_types").val($("#contact_type_description").val()); });
i don't error messages value of select box not set correctly. when debug in console in chrome, get:
> $("#contact_type_description").val() > "office" > $("#contact_types").html() > "<option value="6">home</option><option value="4">mobile</option><option value="5">office</option>"
can tell me i'm doing wrong?
there no <option>
value office, val
looking for, value, not innerhtml.
you can use this:
var thevalue = $("#contact_type_description").val(); $('#contact_types option').filer(function(){ return this.innerhtml === thevalue; }).prop('selected', true);
Comments
Post a Comment