/    Sign up×
Community /Pin to ProfileBookmark

Dynamic Form Select whit three fields

Hi, this is the first time that I write in this forum.
I have a problem…I will build a dynamic form Select whit three fields,where the second field depends on the first one and the third field it depends on the second..I have the code javascript for one dynamic select whit two fields but I need another field.
This is the code that I have…is possible to obtain my aim modifying this code or not?

[B]HTML CODE:[/B]

<form name=”jump”>
<p>
<select name=”region” onChange=”fillCountry()”>
<option value=”1″>Catanzaro
<option value=”2″>Cosenza
<option value=”3″>Crotone
<option value=”2″>Reggio Calabria
<option value=”3″>Vibo Valentia
</select>
<select name=”country”>
<option>————————
<option>————————
<option>————————
<option>————————
<option>————————
<option>————————
</select>
</p>
</form>

[B]SCRIPT CODE:[/B]

<script language=”JavaScript1.2″>
var RegionsDashes = “”
var CountriesDashes = “”
var DefaultLink = “/dest/index.htm”
Countries = new Object()
Links = new Object()

Regions = new Array(“Italy”,”USA”)

Countries[“Italy”] = new Array(“Calabria”,”Campania”);

Links[“Italy”] = new Array(“Calabria”,”Campania”);

Countries[“USA”] = new Array(“Connecticut”,”California”);

Links[“USA”] = new Array(“Connecticut”,”California”);
fillCountry()

function fillCountry(){
document.jump.country.length = 0;
reg = new String(Regions[document.jump.region.selectedIndex])
if (reg == RegionsDashes) {
document.jump.region.selectedIndex = document.jump.region.selectedIndex – 1
reg = new String(Regions[document.jump.region.selectedIndex])
}
document.jump.country.options[0] = new Option(Countries[reg][0],Links[reg][0],1,1);
for(count = 1; count < Links[reg].length; count ++)
document.jump.country.options[count] = new Option(Countries[reg][count],Links[reg][count]);
}
</script>

Thank you…………… ? ?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@sridhar_423Jan 19.2006 — put "onChange="function_name()" in the second select dropdown and use the same logic that you're using to populate the second dropdown.
Copy linkTweet thisAlerts:
@drumskrauthorJan 19.2006 — I have a new problem... I changed the code as:

[B]HTML CODE[/B]

<form name="jump">

<p>

<select name="region" onChange="fillCountry()">

<option value="1">Italy

<option value="2">Usa

</select>

<select name="country" onChange="fillCountry2()">

<option>------------------------

<option>------------------------

<option>------------------------

<option>------------------------

<option>------------------------

<option>------------------------

</select>

<select name="country2" >

<option>------------------------

<option>------------------------

<option>------------------------

<option>------------------------

<option>------------------------

<option>------------------------

</select>

</p>

</form>

[B]JAVASCRIPT CODE[/B]

<script language="JavaScript1.2">

var RegionsDashes = ""

var CountriesDashes = ""

var DefaultLink = "/dest/index.htm"

Countries = new Object()

Links = new Object()

Regions = new Array("Italy","USA")

Countries["Italy"] = new Array("Calabria","Campania");

Links["Italy"] = new Array("Calabria","Campania");

Countries["USA"] = new Array("Connecticut","California");

Links["USA"] = new Array("Connecticut","California");


fillCountry()


function fillCountry(){

document.jump.country.length = 0;

reg = new String(Regions[document.jump.region.selectedIndex])

if (reg == RegionsDashes) {

document.jump.region.selectedIndex = document.jump.region.selectedIndex - 1

reg = new String(Regions[document.jump.region.selectedIndex])

}

document.jump.country.options[0] = new Option(Countries[reg][0],Links[reg][0],1,1);

for(count = 1; count < Links[reg].length; count ++)

document.jump.country.options[count] = new Option(Countries[reg][count],Links[reg][count]);

}

</script>

<script language="JavaScript1.2">

var CountriesDashes = ""

var Countries2Dashes = ""

var DefaultLink = "/dest/index.htm"

Countries2 = new Object()

Links = new Object()

Countries = new Array("Calabria","Campania","Connecticut","California");

Countries2["Calabria"] = new Array("C","Cam");

Links["Calabria"] = new Array("C","Cam");

Countries2["Campania"] = new Array("Conn","Cal");

Links["Campania"] = new Array("Conn","Cal");

Countries2["Connecticut"] = new Array("C","Cam");

Links["Connecticut"] = new Array("C","Cam");

Countries2["California"] = new Array("C","Cam");

Links["California"] = new Array("C","Cam");





fillCountry2()


function fillCountry2(){

document.jump.country2.length = 0;

reg = new String(Countries[document.jump.country.selectedIndex])

if (reg == CountriesDashes) {

document.jump.country.selectedIndex = document.jump.country.selectedIndex - 1

reg = new String(Countries[document.jump.country.selectedIndex])

}

document.jump.country2.options[0] = new Option(Countries2[reg][0],Links[reg][0],1,1);

for(count = 1; count < Links[reg].length; count ++)

document.jump.country2.options[count] = new Option(Countries2[reg][count],Links[reg][count]);

}


</script>

[B][SIZE=4]The problem is that when change the first field I have to adjourn the page to make to correctly work the form[/SIZE][/B]

many many thanks :rolleyes: :rolleyes: :rolleyes:
×

Success!

Help @drumskr 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.19,
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,
)...