473,804 Members | 3,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.valu e == "Other"
{
document.form1. Select2.disable d = true;
}
else
{
document.form1. Select2.disable d = false;
}
}

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

<SELECT name="QuestType " id="select1" tabindex="1" style="width:36 0px;"
required="Y" Description="Qu estion Type"
onchange="javas cript:getQuesti on()">

Any clues or suggestions?

Jul 23 '05 #1
4 5078
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.valu e == "Other"


You've omitted a closing parenthesis.

You can make this simpler:

function getQuestion(con trol) {
control.form.el ements.Select2. disabled = ('Other' == this.value);
}

<select ... onchange="getQu estion(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******** *************@f 14g2000cwb.goog legroups.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.valu e == "Other"
{
document.form1. Select2.disable d = true;
}
else
{
document.form1. Select2.disable d = false;
}
}

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

<SELECT name="QuestType " id="select1" tabindex="1" style="width:36 0px;"
required="Y" Description="Qu estion Type"
onchange="javas cript:getQuesti on()">

Any clues or suggestions?


<html>
<head>
<title>Untitled </title>
<script language="JavaS cript" type="text/javascript">
function getQuestion(){
if (document.form1 .QuestType1.val ue == "2")
{
document.form1. QuestType2.disa bled = true;
}
else
{
document.form1. QuestType2.disa bled = false;
}
}
</SCRIPT>


</head>

<body>
<form action="" name="form1" id="form1">
<select name="QuestType 1" id="QuestType1 " size="1" style="width:36 0px;"
tabindex="1" onChange="javas cript:getQuesti on()" required="Y"
Description="Qu estion Type">
<option value="1" SELECTED>1</option>
<option value="2">2</option>
<option value="3">3</option></select>
<select name="QuestType 2" id="QuestType2 " size="1" style="width:36 0px;"
tabindex="2" required="Y" Description="Qu estion 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
3229
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 column need to be a date picker field. I know things will be easier with ASPX datagrid.
3
6308
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 sending my code here.. Thanks in Advance... Regards
3
3248
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 searches for scripts and html and adapted them. I need to know the principles of how to disable certain options based on other selections within the form. I have attached my script and html below to help. For example of a customer selects (BASIC...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10329
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9163
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7626
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3830
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3000
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.