简体   繁体   中英

Binding a dropdown on the onblur event of a textbox using jquery Ajax

I have a textbox whose value when passed to sp should return a list. I have to bind this list to Dropdown using jQuery Ajax. I have written the sp but my problem is how to bind the dropdown depending on value of textbox in the onblur event of Textbox.

Kindly help. And please excuse for typing errors if any.

i have done similar in my project.

$( "#target" ).blur(function() { alert( "Handler for .blur() called." );

 $.ajax({
                        url: '../GetRolesAndPriviledgeServlet?filepath='+path+'&type='+type,
                        type: 'post',
                        success:function(response){
                            obj = JSON.parse(response);                          

                            $('#DropDownListAssigned').empty(); 

                            for (var i=0; i <obj.length ; i++)
                            {                                               

                                    var oSelField = document.getElementById("DropDownListAssigned");
                                    var oOption = document.createElement("OPTION");
                                    oOption.text = obj[i+1];
                                    oOption.value = obj[i+1];                   
                                    oSelField.options.add(oOption);                                     
                            }
                        },                      
                        error:function(){
                        }
                    }); 

    });

Try this one

   $(document).ready(function () {
      $('#txtboxid').focusout(function () {
          var yourvalue = $('#textboxid').val();
          $.post("/your/url", { Parametername : yourvalue }, function (result) {
              $.each(result, function (key, value) {
                   $('#dropdownid').append($("<option></option>").html(value).val(value)); 
                   // Dropdown Binding
              });
          }, "json");
      });
   });

Note : Parameter must be same as your controller for example public void data(string nval) means your parameter name also nval

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM