user367134
user367134

Reputation: 942

jquery select box help needed

I have select box and option value has

United Kingdom United States

When i select "United Kingdom" as option i want two values "UK" as selected value and param value as 1

Any possiblity using jQuery?

Upvotes: 0

Views: 108

Answers (3)

moleculezz
moleculezz

Reputation: 7703

You could use the .data() function. First you have to set the data on your select options.

<option data-country="UK" data-value="1" selected="selected"></option>

Then you can get that data by doing the following:

$("option:selected").data("country");
$("option:selected").data("value");

Upvotes: 3

Ravi Vanapalli
Ravi Vanapalli

Reputation: 9942

Use an 2D Array and keep both the required values and get both onchange event of dropdown

Upvotes: 0

Val
Val

Reputation: 17522

HTML

<select id="myid">
 <option value="0" class="US">United States</option>
 <option value="1" class="UK">United Kingdom</option>
</select>

jQuery

$('#myid').change(function (){
    var id   = $(this).val(); // 0 or 1
    var code = $(this).attr('class'); //UKorUS
    //do what u like with it
});

Upvotes: 2

Related Questions