How to determine the selected value of the drop-down list

When I select one item from the first drop-down list, the ajax event will occur, will call another function, which will be and load the information into the second drop-down list. I do not want this (without a solution button)

<select id=combo1>
   <option>...</option>
   ...  
</select>
<input type=button onclick="loadCombo2()">
+3
source share
2 answers

If this was implemented in ASP.NET, I would use an HTTP handler to return the JSON data in the second combo box.

Using jQuery, you invoke the handler as follows to implement cascading:

$("#combo1").change(function()
{
    $("#combo2").html("");

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

    if (valueSelected != 0)
    {                 
        $.getJSON('LoadCombo2.ashx?valueSelected=' + valueSelected, function(returnedData)
        {
            $.each(returnedData, function()
            {                        
                $("#combo2").append($("<option></option>").val(this['ID']).html(this['Value']));

            });
        });
    }
});

, HTTP, :
http://www.codedigest.com/Articles/jQuery/224_Building_Cascading_DropDownList_in_ASPNet_Using_jQuery_and_JSON.aspx

, . , , , combobox jQuery.

http://api.jquery.com/jQuery.getJSON/

, .

+1

- :

<select id="combo1" onchange="requestSend(this.value);">
options..........
</select>

<select id="combo2">
options...........
</select>


<script>
  function requestSend(txt)
  {
     $.ajax({
      url:'process.jsp',
      data: "v=" + txt,
      cache:false,
      success: function(response){
       $("#combo2").val(response);
      }
     });
  }
</script>

....

Combo2:

combo2, script, ajax, , php ( , ), - ajax script:

// db queries to get data or whatever
// create a variable that will hold options and shown in combo2

$options = '<option value="whatever">whatever</option>' . "\n";
$options .= '<option value="whatever">whatever</option>' . "\n";
$options .= '<option value="whatever">whatever</option>' . "\n";
//........ etc

// Now we send back the $options variable which will populate the combo2
echo $options;
+2

Source: https://habr.com/ru/post/1734702/


All Articles