/    Sign up×
Community /Pin to ProfileBookmark

drop down issue

i have 2 drop down boxes and i want to disable the second one while selecting any value from first drop down or vice versa.

But not able to find the solution, though i tried the below code but it doesn’t work for me

/* first drop down*/

<select name=”dd1″ id=”dd1″ >
<option value=”0″ selected=”selected”>Select</option>
<option value=”1″> 1 </option>
<option value=”2″ onchange=”disable()”> 2 </option>
</select>

/* 2nd drop down*/

<select name=”dd2″ id=”dd2″ >
<option value=”0″ selected=”selected”>Select</option>
<option value=”1″> 3 </option>
<option value=”2″> 4 </option>
</select>

/*js code*/

function disable()
{
document.frm_contact.dd2.disabled=true;/* frm_contact is a form name*/
}

pls help

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@tirnaMar 11.2010 — Is this what you are after?

The code below will disable the other select list whenever you change the selected value in one of the select lists.

Also, remember to put your JS functions code [B][U]before[/U][/B] they are called anywhere on your page. Usually put them in the <head> section of your XHTML.

Anyway,

<select name="dd1" id="dd1" onchange='document.getElementById("dd2").disabled="true";'>

<option value="0" selected="selected">Select</option>

<option value="1"> 1 </option>

<option value="2"> 2 </option>

</select>

<select name="dd2" id="dd2" onchange='document.getElementById("dd1").disabled="true";'>

<option value="0" selected="selected">Select</option>

<option value="1"> 3 </option>

<option value="2"> 4 </option>

</select>
×

Success!

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