printthis
printthis

Reputation: 151

Change value from dropdown

I want to change the value from a drop-down list via jQuery.

<option value="Yes" data-select2-id="248">Yes</option>

In this instance I want to change the value="Yes" to value="15".

Is there any way to do this?

Upvotes: 0

Views: 46

Answers (3)

printthis
printthis

Reputation: 151

This is what I did with the select2 plugin.

It finds the text of the option and changes the vaule.

$('#Contact').find("option:contains(" + data.FullName +")").attr('value', data.Id).trigger('change');

Upvotes: 0

Lumi Lu
Lumi Lu

Reputation: 3305

$( "option" ).data( "select2-id", 15 );

Upvotes: 0

Matt L.
Matt L.

Reputation: 768

Use .val()

$(<identifier>).val("15");

Here is some reference: http://api.jquery.com/val/

Upvotes: 1

Related Questions