PDA

View Full Version : javascript + form select possibilities


friday
04-09-2004, 07:50 PM
Hey all.

I have the next page with some dropdown boxes (select / option): http://www.abvv-wvl.be/boven.php

I want to disable the second dropdown box when the second option of the first dropdown box is clicked.
But then I want to enable the second dropdown box again, when the first option of the first dropdown box is clicked (eg when the user made a mistake and wants to select another option instead).

Can this be done?

Vincent Puglia
04-09-2004, 09:57 PM
Hi,

I coded it as a function in case you wish to use it for more than one group of 2 selection lists on the same page


<script type='text/javascript'>
function checkit(formObj, ndx, selName)
{
formObj[selName].disabled = (ndx == 2) ? true : false;
}
</script>
</head>
<body>
<form name='theForm'>
<select name="sel1" onchange='checkit(this.form, this.selectedIndex, 'sel2')'>
<option value="">-----</option>
<option value='1'>1</option>
<option value='2'>2</option>
</select>
<select name="sel2">
<option value="">-----</option>
<option value='1'>1</option>
<option value='2'>2</option>
</select>
</form>


Vinny

friday
04-11-2004, 05:12 PM
thanks A LOT!!!

friday
04-11-2004, 06:17 PM
is it possible to make the dropdown box(es) go to the first option (-----) when disabled?
so that the "disability" is more visualized.

agent002
04-11-2004, 06:25 PM
try...
<script type='text/javascript'>
function checkit(formObj, ndx, selName)
{
formObj[selName].disabled = (ndx == 2) ? true : false;
if(ndx == 2) formObj[selName].options[0].selected = true;
}
</script>
</head>
<body>
<form name='theForm'>
<select name="sel1" onchange='checkit(this.form, this.selectedIndex, 'sel2')'>
<option value="">-----</option>
<option value='1'>1</option>
<option value='2'>2</option>
</select>
<select name="sel2">
<option value="">-----</option>
<option value='1'>1</option>
<option value='2'>2</option>
</select>
</form>
:)

friday
04-12-2004, 05:13 AM
wow. thanks!!!

friday
04-22-2004, 09:21 AM
another question regarding this script.
if i select an option, the other dropdown box gets inactive.

that's good of course.

now if i click on the reset button, all dropdown boxes go back to their first state (= good), BUT (!) the boxes that were inactive stay inactive.

i want them to become active again when the reset button is clicked. any idea?

agent002
04-22-2004, 09:47 AM
ok, try this:
<script type='text/javascript'>
function checkit(formObj, ndx, selName)
{
formObj[selName].disabled = (ndx == 2) ? true : false;
if(ndx == 2) formObj[selName].options[0].selected = true;
}

function enableElements(){
for(var i = 0; i < arguments.length; i++){
document.getElementById(arguments[i]).disabled = false;
}
}
</script>
</head>
<body>
<form name='theForm'>
<select name="sel1" onchange='checkit(this.form, this.selectedIndex, 'sel2')'>
<option value="">-----</option>
<option value='1'>1</option>
<option value='2'>2</option>
</select>
<select name="sel2">
<option value="">-----</option>
<option value='1'>1</option>
<option value='2'>2</option>
</select>

<input type="reset" value="Reset" onclick="enableElements('sel2');"
</form>

friday
04-23-2004, 04:52 AM
you're an angel.