Hi,
I have a select box object and an ajax function is called OnChange using the selected value as an input. I also want to call the the same function when the select box is first loaded. I use jQuery .load, but the ajax function is called before any of the options are loaded and the input to my ajax function is undefined. Does anyone know how to get jQuery to wait for all the options to load before calling the function?
Thanks.
Edit - Adding Code
I have found that a setTimeout()
works pretty well to delay the function. However, I get nervous using setTimeout()
because if the page loads slower than usual, it won't work. I tried replacing the timeout with $(document).ready
as you suggested, but the function was still called before an option was selected and the input was undefined.
Here's the code:
<script type="text/JavaScript">
setTimeout('AjaxFunction($("#SelectID option:selected").val()));', 400);
</script>
<select id="SelectID" name="SelectName" onchange="AjaxFunction(this.value);">
<option value='Inland Empire'>Inland Empire</option>
<option value='San Bernardino'>San Bernardino</option>
<option value='Riverside'>Riverside</option>
<option value='California'>California</option>
</select>