473,398 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Javascript Disable Option

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?

Jul 23 '05 #1
4 5052
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

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jul 23 '05 #2

"Quatney" <co*************@sbcglobal.net> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
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>
Jul 23 '05 #3
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.

Jul 23 '05 #4
On 21/07/2005 17:02, Quatney wrote:
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

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: julian.tklim | last post by:
Hi, I need to build an editable Datagrid with add & delete buttons on each row using javascript. DataGrid need not be pre-populated with values. To make the thing complicated, one of the...
3
by: bhanubalaji | last post by:
hi, I am unable to disable the text(label) in javascript..it's working fine with IE,but i am using MOZILLA.. can any one help regarding this.. What's the wrong with my code? I am...
3
by: Venturini | last post by:
I am trying to put together a web page where the customer makes choices of products and is then given a total. I am extremely new to Javascript and have managed to get as far as I have from web...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.