Javascript Disable Option

Q

Quatney

Okay, I'm going nuts here. I know this is VERY easy and I shouldn't
have problems with this, but I can't seem to figure out what I want to
do.

I have a form, with two drop down boxes. I want to be able to disable
the second drop down box when a specific value is chosen on the first.
I can't seem to figure out how to do this.

Go easy on me, I'm a newbie for the most part, but here is my code.

function getQuestion(){
var qSelect = document.form1.QuestText.value
if (document.form1.QuestText.value == "Other"
{
document.form1.Select2.disabled = true;
}
else
{
document.form1.Select2.disabled = false;
}
}

------- Beginning select statement from the first dropdown box

<SELECT name="QuestType" id="select1" tabindex="1" style="width:360px;"
required="Y" Description="Question Type"
onchange="javascript:getQuestion()">

Any clues or suggestions?
 
C

cosmic foo

Quatney said:
Okay, I'm going nuts here. I know this is VERY easy and I shouldn't
have problems with this, but I can't seem to figure out what I want to
do.

I have a form, with two drop down boxes. I want to be able to disable
the second drop down box when a specific value is chosen on the first.
I can't seem to figure out how to do this.

Go easy on me, I'm a newbie for the most part, but here is my code.

function getQuestion(){
var qSelect = document.form1.QuestText.value
if (document.form1.QuestText.value == "Other"
{
document.form1.Select2.disabled = true;
}
else
{
document.form1.Select2.disabled = false;
}
}

------- Beginning select statement from the first dropdown box

<SELECT name="QuestType" id="select1" tabindex="1" style="width:360px;"
required="Y" Description="Question Type"
onchange="javascript:getQuestion()">

Any clues or suggestions?

<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
function getQuestion(){
if (document.form1.QuestType1.value == "2")
{
document.form1.QuestType2.disabled = true;
}
else
{
document.form1.QuestType2.disabled = false;
}
}
</SCRIPT>




</head>

<body>
<form action="" name="form1" id="form1">
<select name="QuestType1" id="QuestType1" size="1" style="width:360px;"
tabindex="1" onChange="javascript:getQuestion()" required="Y"
Description="Question Type">
<option value="1" SELECTED>1</option>
<option value="2">2</option>
<option value="3">3</option></select>
<select name="QuestType2" id="QuestType2" size="1" style="width:360px;"
tabindex="2" required="Y" Description="Question Type">
<option value="1" SELECTED>1</option>
<option value="2">2</option>
<option value="3">3</option> </select>
</form>

</body>
</html>
 
M

Michael Winter

On 21/07/2005 14:48, Quatney wrote:

[snip]
function getQuestion(){
var qSelect = document.form1.QuestText.value

Do you actually use that variable?
if (document.form1.QuestText.value == "Other"

You've omitted a closing parenthesis.

You can make this simpler:

function getQuestion(control) {
control.form.elements.Select2.disabled = ('Other' == this.value);
}

<select ... onchange="getQuestion(this);">

[snip]

Hope that helps,
Mike
 
Q

Quatney

THANK YOU!

I don't know what my deal was, but I thought I had tried this. I did
notice that my "id" and "name" were different on the question types.
That might have been it, but regardless it's working. Thanks again
guys.
 
M

Michael Winter

I don't know what my deal was, but I thought I had tried this.

Tried what, exactly? Please quote when replying: click 'show options',
then the 'Reply' link from this section, not the one at the end of the post.
I did notice that my "id" and "name" were different on the question
types. That might have been it, but regardless it's working.

If a name and id attribute exist together, then for most elements the
values must be identical, however the id and name attributes can be
different on form controls. Consider a group of radio buttons: the
control name must be the same for them to be linked, but their id
attribute values must be different because an id can only occur once in
a document.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top