[email protected]      beta
Donate

Get and Set Dropdown List Selected Value with jQuery

Dropdownlist Get/Set Value: Get and set drop-down box selected value. In web pages while form submission many time we commonly use drop-down list, this post explains how to get / fetch dropdown list selected value. In jQuery we get drop-down list selected by using .`val()` method. The .val() method is primarily used to get the values of form elements such as input, select and text area.

Description: Get the current value of the first element in the set of matched elements.

Html:

//*
<select id="myDlist">
        <option value="1">one</option>
        <option value="2">two</option>
        <option value="3">three</option>
        <option value="4">four</option>
</select>
//*

 jQuery: Here the jQuery code by using .val() method we get the id /value of selected drop-down list,

//*
   // Get the value from a dropdown select
   $('#myDlist option:selected').val();
//*

2nd and easier way

//*
   // Get the value from a dropdown select even easier
   $('#myDlist').val();
//*

Try it Yourself »


Hope you enjoyed this tutorial. If you have any recommendations, please let us know what you think in the comment section below! See you again next time!

 

Share:    
Satinder Singh

Hi all, am Founder and Author of Codepedia.info, also atypical polyglot programmer from Bombay, India. I have a passion to create, solve, and deploy software applications.
       ForEach ( minute in MyLife ) { myExperience++ ; }



Post Comment


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