473,387 Members | 1,899 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,387 software developers and data experts.

single checkbox enable/disable dropdown

I've been looking all over and I can't seem to find what ought to be
simple.

I need to disable a drop down when a checkbox is checked, and enable it
when same checkbox is unchecked.

I've found any number of scripts to disable / enable a drop down but they
are all made to work with 2 different buttons, radio group selections, etc.
I can't seem to come up with one that can toggle off a single checkbox.

help please.

Thanks
Nov 8 '06 #1
2 26292
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Untitled Document</title>
<script type="text/javascript">

window.onload = function() {
document.getElementById('demo').disabled =
document.getElementById('demo_control1').checked;
}

</script>
</head>

<body>

<div id="container">

<select name="demo" id="demo">
<option value="Option 1">Option 1</option>
<option value="Option 2">Option 2</option>
<option value="Option 3">Option 3</option>
<option value="Option 4">Option 4</option>
<option value="Option 5">Option 5</option>
</select>

<label><input type="checkbox" name="demo_control1" id="demo_control1"
onchange="document.getElementById('demo').disabled = this.checked;" />
Activate/Deactivate Selectbox</label>

</div>

</body>
</html>

Kevin wrote:
I've been looking all over and I can't seem to find what ought to be
simple.

I need to disable a drop down when a checkbox is checked, and enable it
when same checkbox is unchecked.

I've found any number of scripts to disable / enable a drop down but they
are all made to work with 2 different buttons, radio group selections, etc.
I can't seem to come up with one that can toggle off a single checkbox.

help please.

Thanks
Nov 8 '06 #2
i would make something more comprehensive to "normal" person :)

something like:

function foo(){
if (document.formname.checkboxname.checked) {
document.formname.dropdownlistname.disabled=true;
}else{
document.formname.dropdownlistname.disabled=false;
}

}

Here ur form tag
..
..
..
<input type="checkbox" name="checkboxname" value="something"
onclick="foo()">
..
..
..
Close form.
neogeek wrote:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Untitled Document</title>
<script type="text/javascript">

window.onload = function() {
document.getElementById('demo').disabled =
document.getElementById('demo_control1').checked;
}

</script>
</head>

<body>

<div id="container">

<select name="demo" id="demo">
<option value="Option 1">Option 1</option>
<option value="Option 2">Option 2</option>
<option value="Option 3">Option 3</option>
<option value="Option 4">Option 4</option>
<option value="Option 5">Option 5</option>
</select>

<label><input type="checkbox" name="demo_control1" id="demo_control1"
onchange="document.getElementById('demo').disabled = this.checked;" />
Activate/Deactivate Selectbox</label>

</div>

</body>
</html>

Kevin wrote:
I've been looking all over and I can't seem to find what ought to be
simple.

I need to disable a drop down when a checkbox is checked, and enable it
when same checkbox is unchecked.

I've found any number of scripts to disable / enable a drop down but they
are all made to work with 2 different buttons, radio group selections, etc.
I can't seem to come up with one that can toggle off a single checkbox.

help please.

Thanks
Nov 8 '06 #3

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

Similar topics

2
by: HolaGoogle | last post by:
Hi all, Can you please tell me what's wrong with my code??? i do have this database in wich i have to field.One is a "yes/no" field and another one is "number" field. To display the yes/no field...
2
by: HolaGoogle | last post by:
Can you please tell me the right way to do this?? it's realy important! thanks in advance... Hi all, Can you please tell me what's wrong with my code??? i do have this database in wich i have...
3
by: Bob Bedford | last post by:
I've this code: function checkdate(FormSubmit){ alert(document.getElementById('Mois').value); if(eval(document.getElementById('Mois'))>0 && eval(document.getElementById('Annee'))>0){...
3
by: Alphonse Giambrone | last post by:
I am trying to enable/disable a requiredfieldvalidator on the client side and am generating an error. I had found some documentation on validation which states that I should be able to...
1
by: hortoristic | last post by:
We are using JavaScript to Enable/Disable certain fields on web pages based on business rules. A simple example is if when using an option type tag, and the two options are Yes and No. If YES...
8
by: John | last post by:
Hello. I have a search form for music albums which among other things I need to search all the song titles of the song. Normally in a search form I would have checkboxes the user can use to...
2
by: RootSpy2006 | last post by:
Hi All, Problem Definition: --------------------- Microsoft Wirelss Keyboard works in BIOS but does not work when booting into windows. Discovered Work-around: -----------------------------...
2
by: Naushad | last post by:
Hi all, I am using the countinous form. I want to Enable/Disable the some fields for perticular records as per the following condition when open the form. I have written this code in "On Current...
3
by: sanndeb | last post by:
I want to enable/disable controls of a asp.net page against a logged in user's permission. say 'admin' & 'hr' can change user's birth date text-box in a page but others will see the text-box as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.