jQuery

Get Select Box Value With jQuery

Use the following jQuery snippet to get the value of the selected option in the select box.

First create a new jQuery function

function getSelectedOption(id){
     $('#' + id).val();
}

Then create your select box.

<select id="selectBox">
    <option>Select</option>
    <option>Red</option>
    <option>Blue</option>
    <option>Green</option>
    <option>Yellow</option>
    <option>Purple</option>
</select>

Now all you have to do to get the selected value for the select box is call the function you just created.

var text = getSelectedOption('selectBox');
Back to top ^

Join Paulund

  • Access 100s of premium tutorials and downloadable content
  • Members content consists of premium WordPress plugins, CSS packages, jQuery packages, tutorial demo files and templates for 100s of web development tutorials
  • In-depth development tutorials
  • Priority tutorial requests
  • No ads

Join Paulund