javascript - Select option get value by text using JQUERY -


this question has answer here:

i have html select (dropdown) many populated options. have table many names button next it. need when press button next name name selected in select box(dropdown). option value id , option text name. example:


!nameslist!v!   <- select box  john  !button! tom   !button! laura !button!     

i have tried use:

var name = "john"; $("#cmboperator option[value='" + name + "']").attr('selected', 'selected');  

but doesn't work. if change var name id(which value) works. how can option's value text?

$("select option:contains(text)").attr('selected', true); 

here jsfiddle

http://jsfiddle.net/u1c21mq6/1/


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -