html - select option while option value equals another class's value via JQuery -


i want create jquery function if 1 drop down value equals value of class, selected.

<input type="hidden" class="target" value="two people"></input> <select id="source">     <option value="one person">one person</option>     <option value="two people">two people</option>     <option value="three people">three people</option> </select> 

in above case, 2 people selected. because used iterated method generate select, can not apply classes option values. doable without classes in options? cheers.

try function http://jsfiddle.net/9z5n5/

$(document).ready(function(){        var target = $('input.target').eq(0).val();      $('#source option').each(function(){           var option = $(this);           if( $(this).attr('value')== target ) option.attr('selected', 'selected');     })  }); 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -