How to detect the selected value from a drop-down list


When I select one item from 1st dropdown, an ajax event will fire up, invoke another function that will and load information to the second dropdown. I do not want this (No button solution please)

<select id=combo1>
<input type=button onclick="loadCombo2()">

If it was being implemented in ASP.NET I'd use an HTTP handler to return the data in JSON format to the second combobox.

Using jQuery you'd call the handler in the following way to implement cascading:


    var valueSelected = $("#combo1").val();

    if (valueSelected != 0)
        $.getJSON('LoadCombo2.ashx?valueSelected=' + valueSelected, function(returnedData)
            $.each(returnedData, function()


To see how to implement the HTTP handler, take a look at a more complete step-by-step in this post:

If you don't need cascading the comboboxes, it gets easier. Just call the handler passing no parameters and load any data you need to fill the second combobox in the callback function of jQuery.

Hope you get the idea.