Click to See Complete Forum and Search --> : Disable Select


comete
08-25-2003, 03:41 PM
How do I disable a select based on the option of another select? I have a form where if you answer no to question 1, you go to question 6. So, if the user answers no to question 1, I would like to disable questions 2 through 5. Some are selects, some are other inputs. But if the user changes the answer to yes, I would like them to be enabled again.

Any thoughts?

Khalid Ali
08-25-2003, 04:17 PM
document.formName.selectName.disabled=true or false;

chose true to make it disabled or false to enable it.

David Harrison
08-25-2003, 04:23 PM
Give each item in the form an id like this:

<input type="text" id="q2ans">

and then you can refer to them and disable them at will:

document.getElementById("q2ans").setAttribute("disabled","disabled");

or:

document.getElementById("q2ans").removeAttribute("disabled");


You could make a fonction that checks each answer to each question and decides whether to disble something or not.


Alternatively you could remove questions altogether by placing every question in a separate div tag like this:

<div id="q1">

What is your name?
<input type="text">

</div>

and then you can hide questions by doing this:

document.getElementById("q1").style.display="none";

and show them again like this:

document.getElementById("q1").style.display="block";

comete
08-26-2003, 08:20 AM
Thanks guys! But I think I didn't phrase my question properly. I got the part on how to disable it, the part I can't fgure out is how to check which option was selected in the dropdown. Here's my dropdown:

<select name="lstQ1" onChange="question1()">
<option value="choose">Choose one</option>
<option value="1">Yes (Go to Question 2)</option>
<option value="0">No (Go to Question 6)</option>
<option value="2">Not sure (Go to Question 6)</option>
</select>

So if the user chooses No or Not Sure, I want to disable stuff, but if the user chooses Yes, I don't want to disable anything. So how do I pass the value of the dropdown to the function to evaluate what what selected?

Thanks is advance!

comete
08-26-2003, 09:05 AM
Never mind, I just figured it out. In my IF, I was using = insead of ==. Been working mostly in ColdFusion lately, have to get back in Javascript mode. Stupid me!!! :D