brocky Posted August 9, 2006 Share Posted August 9, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/16986-help-with-javascriptsqlphp/ Share on other sites More sharing options...
manmadareddy Posted August 9, 2006 Share Posted August 9, 2006 Hi Friend,Please use the following link.View the demo Down load all the files and check.http://duvinci.com/projects/ajax/dropdowns/ Quote Link to comment https://forums.phpfreaks.com/topic/16986-help-with-javascriptsqlphp/#findComment-71621 Share on other sites More sharing options...
brocky Posted August 9, 2006 Author Share Posted August 9, 2006 Thanks but i couldn't get the demo code to work any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/16986-help-with-javascriptsqlphp/#findComment-71645 Share on other sites More sharing options...
radalin Posted August 9, 2006 Share Posted August 9, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/16986-help-with-javascriptsqlphp/#findComment-71658 Share on other sites More sharing options...
Guest huey4657 Posted August 9, 2006 Share Posted August 9, 2006 Try this: [url=http://javascripttoolbox.com/lib/dynamicoptionlist/examples.php]http://javascripttoolbox.com/lib/dynamicoptionlist/examples.php[/url] Quote Link to comment https://forums.phpfreaks.com/topic/16986-help-with-javascriptsqlphp/#findComment-71665 Share on other sites More sharing options...
brocky Posted August 9, 2006 Author Share Posted August 9, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/16986-help-with-javascriptsqlphp/#findComment-71686 Share on other sites More sharing options...
radalin Posted August 9, 2006 Share Posted August 9, 2006 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']. Quote Link to comment https://forums.phpfreaks.com/topic/16986-help-with-javascriptsqlphp/#findComment-71727 Share on other sites More sharing options...
brocky Posted August 11, 2006 Author Share Posted August 11, 2006 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 meRegards,Glenn Quote Link to comment https://forums.phpfreaks.com/topic/16986-help-with-javascriptsqlphp/#findComment-72825 Share on other sites More sharing options...
radalin Posted August 11, 2006 Share Posted August 11, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/16986-help-with-javascriptsqlphp/#findComment-72907 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.