Jump to content


Photo

Help with Javascript/SQL/PHP


  • Please log in to reply
8 replies to this topic

#1 brocky

brocky
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationAustralia

Posted 09 August 2006 - 03:25 AM

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: nerd_central@hotmail.com

#2 manmadareddy

manmadareddy
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 09 August 2006 - 05:04 AM

Hi Friend,
Please use the following link.View the demo
Down load all the files and check.
http://duvinci.com/p...ajax/dropdowns/

#3 brocky

brocky
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationAustralia

Posted 09 August 2006 - 07:25 AM

Thanks but i couldn't get the demo code to work any ideas?

#4 radalin

radalin
  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts

Posted 09 August 2006 - 08:47 AM

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
Roy Simkes
Yet Another Parkyeri Developer

#5 Guest_huey4657_*

Guest_huey4657_*
  • Guests

Posted 09 August 2006 - 09:20 AM

Try this: http://javascripttoo...st/examples.php

#6 brocky

brocky
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationAustralia

Posted 09 August 2006 - 10:46 AM

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

#7 radalin

radalin
  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts

Posted 09 August 2006 - 11:55 AM

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'].
Roy Simkes
Yet Another Parkyeri Developer

#8 brocky

brocky
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationAustralia

Posted 11 August 2006 - 02:03 AM

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

#9 radalin

radalin
  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts

Posted 11 August 2006 - 07:55 AM

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.
Roy Simkes
Yet Another Parkyeri Developer




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users