开发者

onchange on dropdownlist

开发者 https://www.devze.com 2022-12-27 15:29 出处:网络
my question is continuation of what i have asked see the link. Load Country/State/City i have expand to load my drop downs list from db and i just need a way to wire onchange method in my first dropd

my question is continuation of what i have asked see the link. Load Country/State/City

i have expand to load my drop downs list from db and i just need a way to wire onchange method in my first dropdownlist and second, please see the code. appreciate any help.

Append latest code:

<select id="country"  onchange="getStateByCountryId()"></select> <br />
<select id="state"></select>  <开发者_JS百科;br />


$(document).ready(function() { 
     var options = {
         type: "POST",
         url: "SearchPage.aspx/LoadCountry",
         data: "{}",
         contentType: "application/json; charset=utf-8",
         dataType: "json",

         success: function(msg) {

             var returnedArray = msg.d;
             country = $("#country"); 
              country.append('<option>Select a Country</option>'); 

             for (i = 0; i < returnedArray.length; i++) {
                  country.append("<option value='" + returnedArray[i].Id + "'>" + returnedArray[i].Name + "</option>");
             }


         }
     };
     $.ajax(options);
 });


function getStateByCountryId() {

     $("#country").change(function() 
     { 
         var _selected = $("#country").val();
         var options = 
         {
             type: "POST",
             url: "SearchPage.aspx/StateBy",
             data: "{'countryId':'" + _selected + "'}",
             contentType: "application/json; charset=utf-8",
             dataType: "json",

             success: function(msg) {
                $('#state').empty(); 
                 var returnedArray = msg.d;


                 state = $("#state");
                 for (var i = 0; i < returnedArray.length; ++i) {
                     state.append("<option value='" + returnedArray[i].Id + "'>" + returnedArray[i].Name + "</option>");
                 }
             }
         };
         $.ajax(options);
     });
 }

but does not populate? the way i am doing is that how you suppose to do?

thanks.


$("#state").change(function(){
    //on-change code goes in here.
    //variable "this" references the state dropdown element
});


$(this).parent("select").attr("id");
0

精彩评论

暂无评论...
验证码 换一张
取 消