Posted injQuery / JavaScript

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.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype