/    Sign up×
Community /Pin to ProfileBookmark

add value to a combobox based on value selected in another combo box

hi,

i have two combo boxes. my first combo box lists the state name and my second combo box list the city names. if i select the state name as “mumbai” the particular cities should add up in the city combo box. i have used addItem() method and onChange() event of “state” combobox. but it is not working.

here is my code:

html:

<form name=”combobox_validation”>
Select state <select name=”selectstate” onChange=”return comboBoxValidation()”>
<option value=”select a state” selected=”true”>select a state</option>
<option value=”tamil nadu”>Tamil Nadu</option>
<option value=”andhra pradesh”>Andhra Pradesh</option>
<option value=”kerala”>Kerala</option>
<option value=”karnataka”>Karnataka</option>
</select>
Select city <select name=”city”>
<option value=”select a city” selected=”true”>select a city</option>
city.addItem(“chennai”);
</select>
</form>

javascript:

function comboBoxValidation()
{
if(document.combobox_validation.selectstate.selectedIndex==1)
{
document.combobox_validation.city.addItem(“chennai”);
document.combobox_validation.city.addItem(“kovai”);
}
}

please help me…

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@gabrieleJul 02.2008 — firstly you have a city.addItem("chennai") under you first option in the city dropdown.. (this should not be there .. )

second, the way to add options is the following

[I]document.combobox_validation.city.options.add( new Option('chennai','chennai') );[/I]

take a look here (url: http://www.devguru.com/Technologies/ecmaScript/quickref/option.html ) for the syntax of Option method ..

hth
Copy linkTweet thisAlerts:
@vaishnaviauthorJul 03.2008 — thank you gabriele, its working.
×

Success!

Help @vaishnavi 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.28,
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,
)...