Delphinidin

Get any informations you need in depth explanation

Using jQuery to retrieve the value from a select option is also simple to set up, yet can be very useful in any type of Web site or application. An example of this functionality can be seen on Crutchfield.com, a car and home audio electronics Web site, in the Outfit Your Car section. Crutchfield allows you to select your car year, model, and make — each time you make a selection, the value of the select option a retrieved and then used to display another option with list items that are filtered by the previous select.

1. Set up the HTML form select element that will be used to retrieve the value of the selected option:

<select id="my-select" name="question1">
<option value="yes">yes</option>
<option value="no">no</option>
</select>

2. Set up a selector statement that selects the my-select element and attach a change event to it.

$('#my-select').change(function() {
});

3. Add a variable to the change event handler called selectVal and make it equal to this value (the one that is being selected):

$('#my-select').change(function() {
var selectVal = $(this).val();
alert(selectVal);
});

0 comments:

Post a Comment

Site Info