Gossamer Forum
Home : Products : DBMan : Customization :

Adding DHTML to script

Quote Reply
Adding DHTML to script
On my index.html page I have a dynamic dropdown list for my STATES field, showing just the STATES that are recorded in my .db file. I was using CITY also, but problem was, it listed every city but I couldn't figure out how to add an abbreviated STATE name to the end of it.... http://www.choiceretreats.com

What I'm wondering and maybe I'm in the wrong area, I want you the user to choose a state then below it, load the Cities into another dropdown list box below showing just the cities for that state?

Any ideas?

Thanks
Theri

PS...I have been at FAQ site and no luck.



Quote Reply
Re: Adding DHTML to script In reply to
You should be able to adapt this script to your needs...

http://javascript.internet.com/forms/country.html

Quote Reply
Re: Adding DHTML to script In reply to
Hey oldmoney and thanks. Let me go one step further. Do you think I can work this code into my subroutines. I like what I see in this Javascript, just trying to think how I could manipulate it so it would load Cities just recorded in the dbase.

Theri


Quote Reply
Re: Adding DHTML to script In reply to
Depending on how many unique city entries you have per state, this Javascript could get pretty slow (10-20 is cool, 100+ would be real slow). But in any event you should be building the arrays on the fly... I'll save you a step and cut out the three-tiered structure on JavaScript Source. Below is a two-tiered, which is closer to where you want tot get to (if country=US, pick a State, else just choose country)...

Code:
print qq~
<SCRIPT LANGUAGE="JavaScript">
function populateUSstate(inForm,selected) {
var stateArray = new Array("('Select...','',true,true)",
"('AL')",
"('AK')",
"('AZ')",
"('AR')",
"('CA')",
"('CO')",
"('CT')",
"('DE')",
"('DC')",
"('FL')",
"('GA')",
"('HI')",
"('ID')",
"('IL')",
"('IN')",
"('IA')",
"('KS')",
"('KY')",
"('LA')",
"('ME')",
"('MD')",
"('MA')",
"('MI')",
"('MN')",
"('MS')",
"('MO')",
"('MT')",
"('NE')",
"('NV')",
"('NH')",
"('NJ')",
"('NM')",
"('NY')",
"('NC')",
"('ND')",
"('OH')",
"('OK')",
"('OR')",
"('PA')",
"('RI')",
"('SC')",
"('SD')",
"('TN')",
"('TX')",
"('UT')",
"('VT')",
"('VI')",
"('WA')",
"('WV')",
"('WI')",
"('WY')");
if (selected == 'USA') {
for (var i=0; i < stateArray.length; i++) {
eval("inForm.State.options=" + "new Option" + stateArray);
}
if ( navigator.appName == 'Netscape') {
if (parseInt(navigator.appVersion) < 4) {
window.history.go(0)
}
else {
if (navigator.platform == 'Win32' || navigator.platform == 'Win16') {
window.history.go(0)
}
}
}
}
else {
}
if (selected == 'Other...') {
newCountry = "";
while (newCountry == ""){
newCountry=prompt ("Please enter the name of the country...", "");
}
if (newCountry != null) {
inForm.State.options[(inForm.State.options.length-1)]=new Option(newCountry,newCountry,true,true);
}
}
if(inForm.State.options[0].text == 'Select...') {
inForm.State.options[0]= null;
}
}
</script>
<select name="State" onChange="populateUSstate(document.form1,document.form1.State.options[document.form1.State.selectedIndex].text)">
<option selected value=''>Select...</option>
<option value='USA'>USA</option>
<option value='Canada'>Canada</option>
<option value='United Kingdom'>United Kingdom</option>
<option value='Israel'>Israel</option>
<option value='Other...'>Other...</option>
</select>~;