tags:

views:

299

answers:

2

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.

Thanks for your help!

A: 

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();

alex
ar_form basically displays <TR > <TD width="40%"><? print $strFieldName; ?></TD> <TD width="60%"><input type="text" name="<? print $ar_row['field']; ?>" id="<? print $ar_row['field']; ?>" value="<? print $ar_row['value']; ?>" ></TD> </TR>
Jon Schenk
with blank params it will display the table elements based on a default value...so if nothing is posted to ar_form, it will display it based on a default value....
Jon Schenk
@Jon, is that going to be a problem ?
alex
i don't see how this will work. Don't i need to "load" the data initially?
Jon Schenk
Well if you call the change event, if should request your ar_form.php file with (supposedly) idata: '', which may do what you're requiring.
alex
i'll try and let you know.
Jon Schenk
is there a way to check to see if a div elememt has html content?
Jon Schenk
yes, if ($('#id').html()) { // has content; }
alex
+1  A: 
$("#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");
duckyflip
Your are the man! Worked perfectly!
Jon Schenk