O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting and Setting Select Values

var value = $("#singleSelect").val(); var values = $("#multiSelect").val(); . . . $("#singleSelect").val("one"); $("#multiSelect").val(["two", "three"]);

Select inputs are really container inputs for a series of <option> elements. The value of the select element is the value(s) of the currently selected option(s). Once again, the submission and serialization in jQuery and JavaScript handle this automatically for you. However, doing it manually requires a bit of code.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required