single checkbox enable/disable dropdown

K

Kevin

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
 
N

neogeek

<!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>
 
R

Ruso

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.
 

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
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top