Hey guys;

So I've started using the uber cool xmlHTTPRequest on one of my forms to populate a select field. It works really well and I'm surprised how seamless it all is... I do need some suggestions on use.

Here's my situation:

I have a Country select field that is populated by a mysql request - the options here are loaded and one of them is selected based on the users' default value.

Based on this value (country) the State select field populates itself with the states for that respective country and even select the default state for the user. This select field is populated by my xmlhttprequest friend.

I have this all working. However, I currently have to have the user click on the EMPTY State select field in order to load the states... looks kinda lame.

I use the "onChange" function to call my loadXMLDoc() method... which in turn pulls the states based on the selected Country value.

Here's my problem:

In order to populate the state field, I need an event handler to initiate the loadXMLdoc() function ... ala "onChange", "onClick", etc.

If I DONT auto-select the country field and let the user do it, I can use onChange and load the states for that particular country. This works for the New Profile form, but it doesn't work for the Edit Profile form which should auto-select everything and show the user his previously selected values.

So my question is, what's the best approach to have the states load when the form is loaded? Based on what country is automatically selected... ?

I have thought of using onLoad() for the BODY tag, but since it the BODY comes from a global include, I don't want to clutter it with functions I don't really need for a lot of pages.

Is there any way to access this data without going through "onchange" or the like?

Is there a better way to do what I want?

Thanks!

Rafael.

    Hahaha.. Ok, I'm dumb... solved my own problem.

    I just insert:

    <script type="text/javascript">loadXMLDoc()</script>

    right before the State select field and it works now.

    Thanks.

      Write a Reply...