Jump to content

Archived

This topic is now archived and is closed to further replies.

brocky

Help with Javascript/SQL/PHP

Recommended Posts

I need help with a javascript problem that also includes PHP and SQL.

The problem being is that i've got three drop down boxes: the first a country, the second a state/region, and the third is a city. I need it to so when you select a country the states from that country appear in the second drop down box and when you select a state the cities of that state appear in the third drop down box. All this has to be done without reloading the page if possible.

I've so far got it to do the selection part and all but it has to reload the page every time it is changed and deletes all user information that was already entered in the form.

If you need the source code as well please email me for it.

If you have any ideas about this problem please post here ,email, or pm me at: [b]nerd_central@hotmail.com[/b]

Share this post


Link to post
Share on other sites
Hi Friend,
Please use the following link.View the demo
Down load all the files and check.
http://duvinci.com/projects/ajax/dropdowns/

Share this post


Link to post
Share on other sites
Thanks but i couldn't get the demo code to work any ideas?

Share this post


Link to post
Share on other sites
That's quite easy to do with an XMLHTTPRequest Object or AJAX with it's popular name.

at ajaxfreaks.com you can find an easy tutorial to how it can be done. All you have to do is to add a onChange event to your dropdown boxes. And then you script will take the value of your dropdown box send it to a php page (like findState.ajax.php) via get mode (your url will be as findState.ajax.php?country=USA) and in your PHP page you will get data from SQL and then echo the options. Get the text by XMLHTTPRequest's responseText property and add it to your page via an innerHTML method of a span area, or something like that.

look for ajaxfreaks.com for a more clear tutorial btw

Share this post


Link to post
Share on other sites
Guest huey4657
Try this: [url=http://javascripttoolbox.com/lib/dynamicoptionlist/examples.php]http://javascripttoolbox.com/lib/dynamicoptionlist/examples.php[/url]

Share this post


Link to post
Share on other sites
Ok ive got to the AJAX stage and have done a fair bit in it but im stuck again.
Im needing a form that has three drop down boxes not two and don't quiet understand how this works. please email me if you have any suggestions. Ive also got the source code for all + sql database structure. Just i can't post it on the net anywhere

Share this post


Link to post
Share on other sites
well in your second dropdown box add another onchange event which will call the same function but this time instead of findState.ajax.php?country=USA use findState.ajax.php?state=California. Take a paramater with you js function if it's higher than one then this is country dropdown it it's lesser then this is the state dropdown who is calling our function. And in your php do something else if $_GET['country'] or $_GET['state'].

Share this post


Link to post
Share on other sites
Ok i've almost got it finished. I just can't get the value from the last drop down box in the form. Even when i print out all post values and keys there is no $_POST['city']. Does any1 no why this is or how to fix it?

If you have any ideas please post here or email me

Regards,
Glenn

Share this post


Link to post
Share on other sites
You should have probably mistaken the <select>'s name in the "findState.php" file. In the section of $_get['state'] check what you echo. (or I mean what it does return as text). Probably it's "City" instead of "city" or something like that.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.