[NWS] Select Boxes question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wizzard
Forum Commoner
Posts: 93
Joined: Thu May 16, 2002 5:36 am
Location: Belgium
Contact:

[NWS] Select Boxes question

Post by wizzard »

Hello,

I have 2 select boxes state/county and country. I want if a user select the country he lives in then the states/countys must be showed in the county select box. All the data is stored in a database.

Can someone helps me with this?


Cheers
Kris
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Javascript requred:

example : http://www.mattkruse.com/javascript/dynamicoptionlist/

You could get the options in PHP and place them as a javascript array in the page.

Regards
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Ya, javascript. Something like:

Code: Select all

<script>
function update_state(s_country)
&#123;
    if(country == "Canada")
    &#123;
       var wrapper = document.getElementbyID('state_wrapper');
        ...... 
        //go about re-writing the innerHTML of wrapper
   &#125;
   .......
&#125;
</script>

<select name = "country" onChange = "update_state('this.value')">
......
</select>
<div id = "state_wrapper">
<select name = "state">
........
</select>
</div>
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Eek, sorry Pickle but doesn't InnerHTML throw some errors depending on what browser you have. There are far easier ways of doing it as shown by the link which use only core javascript that every browser (with javascript switched on) is OK with.

Now thats a though Wizzard, have you got a solution if users haven't swicthed on javascript?
wizzard
Forum Commoner
Posts: 93
Joined: Thu May 16, 2002 5:36 am
Location: Belgium
Contact:

Post by wizzard »

Not yet CoderGoblin its indeed a problem if users have javascript off.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

CoderGoblin wrote:doesn't InnerHTML throw some errors depending on what browser you have.
Quite possibly - that's just the only thing I could think of at the time :)
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
wizzard
Forum Commoner
Posts: 93
Joined: Thu May 16, 2002 5:36 am
Location: Belgium
Contact:

Post by wizzard »

[NWS] link its something like this i want the state / province and country select box. Thats easy for my visitors. I have taked this one out of the adultfriendfinder website as example its not mine :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

take care when posting links like that wizzard.. this is a site accessed by people at businesses.
wizzard
Forum Commoner
Posts: 93
Joined: Thu May 16, 2002 5:36 am
Location: Belgium
Contact:

Post by wizzard »

i'm very sorry for that but it was necesarry to show what i mean with the select boxes.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

from another thread:
wizzard
Forum Commoner
Posts: 93
Joined: Thu May 16, 2002 5:36 am
Location: Belgium
Contact:

Post by wizzard »

Ok thanks so this means you have to first grab everything out from the database the country list and the states/provinces you cannot do this on refresh via javascript and take the data out from the database when a country is selected?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

In order to make it responsive, and less headache for you in processing, yes, you'll need to load all the combinations for javascript. Otherwise, you'll have to ask Javascript to submit the form every time a country is selected to refresh the state list..
Post Reply