Page 1 of 1
Dynamicly update secondry box from selection.
Posted: Thu Apr 29, 2010 2:51 am
by scorpio90
Hi guys,
Does anyone know of a java or php code that..
At the moment i have a dynmic option box, but when selected could update into a secondry option box.
For example,
If i was filling out a form and i had a option to chose my country .. say for example England.. then the secondary box will automatically populate with all the counties in England which then i could select in the secondary option box.
Any help would be great

Thankyou.
Re: Dynamicly update secondry box from selection.
Posted: Fri Apr 30, 2010 9:56 am
by katierosy
Please see jquery.com library , and it's ajax call methods in it's tutorials.
If you will call second select box from another file say x.php with <?php echo $var = '<options value="helo">Helo</options><options value="helo1">Helo1</options><options value="helo2">Helo2</options>'; ?> for example.
You will accomplish, what is needed.
Re: Dynamicly update secondry box from selection.
Posted: Fri Apr 30, 2010 10:17 am
by hypedupdawg
Yes - you wont be able to do this using PHP as all PHP code is executed on the server-side. To use a php script to re-populate the boxes, you would have to refresh the page each time, using a $_POST or $_GET method. While this is something a lot of forms seem to do, it is much better for you to use a client-side method to do this (e.g. the javascript innerHTML property).
Re: Dynamicly update secondry box from selection.
Posted: Fri Apr 30, 2010 11:06 pm
by Jonah Bron
First of all, Java is not Javascript. They are completely different. I know that doesn't make any sense, but that's how it is.
Like the previous posters stated, you will need to call to get the countries/counties with AJAX. Have a file called "countries.txt", with all of the countries you want listed. Then, create a folder called "countries", and populate it with files like "england.txt", "poland.txt", "yugoslavia.txt", etc. Each of those text files will contain the counties of their respective countries. You will use Javascript/AJAX to call the right country file, depending on the user's country selection (the onchange event of the country selection box), and fill up the county selection box with the results.
Using
Mootools or
jQuery make the AJAX much easier.