/    Sign up×
Community /Pin to ProfileBookmark

Advanced Forms Question

I need to create a form that has a selectbox for states, and when you select a state the cities for that state come up in another selectbox.

I’m not picky about how it gets done, they easiest way is fine, I’m open to all suggestions.

to post a comment
HTML

2 Comments(s)

Copy linkTweet thisAlerts:
@BlueRainJun 09.2005 — See [URL=http://www.quirksmode.org/dom/usableforms.html]Usable Forms[/URL]
Copy linkTweet thisAlerts:
@jalarieJun 10.2005 — Perhaps the dummy contest on my site will point you in a usable direction:

function PickPrize2() {
f1=document.forms[0]; // abbreviation
for (ix1=f1.contest2.options.length; ix1>=0; ix1=ix1-1) {
f1.contest2.options[ix1]=null;
}
ix1=f1.contest1.selectedIndex;
PrizeCar=f1.contest1.options[ix1].text;
for (ix1=0; ix1<Prizes.length; ix1++) {
Prize=Prizes[ix1];
PrizeItems=Prize.split(/,/);
if (PrizeItems[0] == PrizeCar) {
for (ix2=1; ix2<PrizeItems.length; ix2++) {
ix3=ix2-1;
f1.contest2.options[ix3]=new Option();
f1.contest2.options[ix3].text=PrizeItems[ix2];
}
}
}
}
Prizes=new Array(
'',
'Ferrari,Enzo,Maranello',
'Lamborghini,Murcielago,Diablo',
'Porsche,Carrera GT,911 Turbo'
);
document.write('If I win the contest, I'd like a n');
document.write('<select name="contest1" id="contest1" onchange="PickPrize2();">n');
for (ix1=0; ix1<Prizes.length; ix1++) {
Prize=Prizes[ix1];
PrizeItems=Prize.split(/,/);
document.write(' <option>'+PrizeItems[0]+'</option>n');
}
document.write('</select>n');
document.write(' model n');
document.write('<select name="contest2" id="contest2">n');
document.write(' <option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</option>n');
document.write(' <option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</option>n');
document.write(' <option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</option>n');
document.write('</select>n');
document.write(' for my very own.n');
document.write('<br /><br />n');
×

Success!

Help @unurban spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...