Jump to content

Help with Javascript/SQL/PHP


brocky

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]
Link to comment
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
Link to comment
Share on other sites

Guest huey4657
Try this: [url=http://javascripttoolbox.com/lib/dynamicoptionlist/examples.php]http://javascripttoolbox.com/lib/dynamicoptionlist/examples.php[/url]
Link to comment
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
Link to comment
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'].
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.