jquery set select option value

0
()

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();

Free Live Chat for Any Issue

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:

<select name="liveproduct" id="liveproduct">
    <option value="1">Laptop</option>
    <option value="2">Computer</option>
    <option value="3">Mobile</option>
    <option value="4">Iphone</option>
</select>

//jquery code

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

Download

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.

Read Also:  Pop Push Shift Unshift Array Methods

How useful was this post?

Click on a star to rate it!