1

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.

Community
  • 1
  • 1
user2470026
  • 157
  • 1
  • 7

1 Answers1

3

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") );
ebilgin
  • 1,242
  • 10
  • 19