enable and disable drop down list in php/javascript

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
ananth_ak
Forum Newbie
Posts: 23
Joined: Wed Feb 09, 2005 12:42 pm
Location: uk, london
Contact:

enable and disable drop down list in php/javascript

Post by ananth_ak »

hi,

i'm trying to do enable and disable on two drop down lists,
where initially combo1 is enabled and combo2 is disabled
once selection has been made in combo1, combo2 is enabled..

is there any php/html/javascript solutions for this?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

untested....

Code: Select all

<script language=&quote;JavaScript&quote;>

function enableformObj(formObjName){
	
	document.getElementById(formObjName).disabled = false;
}

</script>

<select name=&quote;list1&quote; onBlur=&quote;enableformObj('list2');&quote;>
    <option value=&quote;1&quote;>1</option>
    <option value=&quote;2&quote;>2</option>
    <option value=&quote;3&quote;>3</option>
  </select><select name=&quote;list2&quote; id=&quote;list2&quote; disabled>
    <option value=&quote;a&quote;>a</option>
    <option value=&quote;b&quote;>b</option>
    <option value=&quote;c&quote;>c</option>
  </select>
ananth_ak
Forum Newbie
Posts: 23
Joined: Wed Feb 09, 2005 12:42 pm
Location: uk, london
Contact:

Post by ananth_ak »

hi, thanks for the solution.

it works only when you double click. cant see where in the script i can change it to a single click.
ananth_ak
Forum Newbie
Posts: 23
Joined: Wed Feb 09, 2005 12:42 pm
Location: uk, london
Contact:

Post by ananth_ak »

It's alright i found it.

onChange instead of onBlur

<select name="list1" onChange="enableformObj('list2');">

thanks very much!
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Use this reference for event handlers:

http://www.devguru.com/Technologies/ecm ... ndler.html
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Moved to Client-Side
ananth_ak
Forum Newbie
Posts: 23
Joined: Wed Feb 09, 2005 12:42 pm
Location: uk, london
Contact:

Post by ananth_ak »

hi,

now that i have one enabled drop down and one disabled drop down

how do i bring up a list of items in the second drop down box based on a selection from the first drop down box.

if drop box 1 = A
then drop box 2 = 1,2,3,4
or

if box 1 = B
then box 2 = 5,6,7,8
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

There is a tutorial for this at

viewtopic.php?t=29084 :wink:

If you have any comments on the tutorial let me know (possibly private message) as so far no feedback has been received.
Post Reply