jquery set select option value

Today, We want to share with you jquery set select option value.In this post we will show you jquery set dropdown selected value by value, hear for How to programmatically set the value of a select box element using JavaScript? we will give you demo and example for implement.In this post, we will learn about Get Selected Option Value Jquery Example with an example.

Get and Set the select box options using jQuery

GET SELECTED OPTION VALUE USING JQUERY:

$('#liveproduct').val();

GET SELECTED OPTION TEXT USING JQUERY:

$('#liveproduct > option:selected').text();

SET SELECTED OPTION TEXT USING JQUERY:

var arg ='option Text';
 $('#liveproduct > option').each(function(){
 if($(this).text()==arg) $(this).parent('select').val($(this).val())
 })

SET SELECTED OPTION VALUE USING JQUERY:

var arg ='option value';
 $('#liveproduct').val(arg)

GET SELECTEDINDEX USING JQUERY:

$('#liveproduct > option:selected').prevAll().length

SET SELECTEDINDEX USING JQUERY:

var index =3;
 $('#liveproduct > option').eq(index).attr('selected','selected')

Change selected option by value on select list with jQuery

Example 2:



//jquery code

$("#liveproduct option[value=3]").attr('selected', 'selected');
 
// Or just...
$("#liveproduct").val(3);

I hope you get an idea about jquery set dropdown selected value by text.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment