How to preload combo box div in jquery

I have code like this:

$("#item_select").change(function() 
{ 
    var params = $("#item_select option:selected").val();
    $.post('/account/ar_form.php', {idata: params},  function(data){
        $("#message_display" ).html(data);
    });
}); 

      

This is the dropdown that uses / account / ar _form.php to display the html in the div correctly.

But it only shows up in the change event. I would like it to preload the data. When I use the load event, it displays the html, but when changed, it displays it twice.

0


a source to share


2 answers


$("#item_select").change(function(){ 
    var params = $("#item_select option:selected").val();
    $.post('/account/ar_form.php', {idata: params},  function(data){
        $("#message_display" ).html(data);
    });
}).triggerHandler("change");

      



+1


a source


It depends a little ... what does your ar_form.php return with empty parameters?

You can do a hacky way (for fear of being overwhelmed) by calling



$("#item_select").change();

0


a source







All Articles