Page 1 of 1

[NWS] Select Boxes question

Posted: Thu Aug 12, 2004 7:29 am
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

Posted: Thu Aug 12, 2004 8:15 am
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

Posted: Thu Aug 12, 2004 9:33 am
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>

Posted: Thu Aug 12, 2004 9:43 am
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?

Posted: Thu Aug 12, 2004 10:10 am
by wizzard
Not yet CoderGoblin its indeed a problem if users have javascript off.

Posted: Thu Aug 12, 2004 10:39 am
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 :)

Posted: Thu Aug 12, 2004 4:14 pm
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 :)

Posted: Thu Aug 12, 2004 4:20 pm
by feyd
take care when posting links like that wizzard.. this is a site accessed by people at businesses.

Posted: Thu Aug 12, 2004 5:43 pm
by wizzard
i'm very sorry for that but it was necesarry to show what i mean with the select boxes.

Posted: Thu Aug 12, 2004 6:41 pm
by feyd
from another thread:

Posted: Fri Aug 13, 2004 8:02 am
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?

Posted: Fri Aug 13, 2004 11:21 am
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..