Reputation: 157
Here is the small code which was trying. In this we have multiple value for all the select options. I get this idea from this Can an Option in a Select tag carry multiple values? . Please help me out with this i'm new to jquery.
<select id="gate">
<option value='null'>- choose -</option>
<option value='Gateway 1,Gateway 3'>Gateway 1</option>
<option value='Gateway 2,Gateway 4'>Gateway 2</option>
</select>
$("#gate").val('Gateway 3');
The result got is empty in the drop down.
Upvotes: 1
Views: 141
Reputation: 1252
You can do it with this.
$("#gate").val( $("#gate option[value*='Gateway 3']").attr("value") )
JS Fiddle
http://jsfiddle.net/ebilgin/zLh92h6b/1/
With variable
var str = "Gateway 3";
$("#gate").val( $("#gate option[value*='" + str + "']").attr("value") );
Upvotes: 3