469,950 Members | 2,061 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

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 25970
<!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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Bob Bedford | last post: by
3 posts views Thread by Alphonse Giambrone | last post: by
1 post views Thread by hortoristic | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.