Question

I have code as follows:

$("#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 a dropdown that uses /account/ar_form.php to display html in the div correctly.

But it only displays on the change event. I'd like it to preload the data. When I use a load event, it will display the html, but on change, it displays it twice.

Was it helpful?

Solution

$("#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");

OTHER TIPS

It depends a bit... what does your ar_form.php return with blank params?

You could do a hackish way (at fear of being downvoted) by calling

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow