Forum Moderators: not2easy
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<style type="text/css">
body{
font:70%/1.7 Tahoma, Verdana, sans-serif;
background:#369;
color:#fff;
}
#menu{
width:500px;
}
input.disabled{
background:#000;
/*display:none; uncomment this to get rid of the input box, altogether*/
}
</style>
<script type="text/javascript">
function visiblyDisableInput(inputName){
all_inputs = document.getElementsByTagName('input');
for(j=0;j<all_inputs.length;j++){
if(all_inputs[j].className == "meat"){
all_inputs[j].className = "disabled";
}
}
}
</script>
</head>
<body>
<div id="menu">
<form name="myMenu">
<fieldset><legend>Make selections to build your dinner menu:</legend>
<p>Are you a vegetarian? <label>Yes: <input type="checkbox" onClick="visiblyDisableInput('this_box')" /></label> <label>No: <input type="checkbox" /></label></p>
<p>Would you like your steak rare, medium, or well-done? <input type="text" name="steak" class="meat" /></p>
<p>Do you prefer steamed or fried shrimp? <input type="text" name="shrimp" class="meat" /></p>
<p>What would you like on your baked potato? <input type="text" name="potato" class="potato" /></p>
</fieldset>
</form>
</div>
</body>
</html>
Obviously, this should use radio buttons, not checkboxes, but since you asked specifically about checkboxes...
cEM
Is there anyway you can get the boxes to return back to normal when the box is unchecked.
Is there anyway you can get the boxes to return back to normal when the box is unchecked.
This makes this question a javascript one, since the script is doing the work of manipulating classes to which CSS is attached. I only mention this because I am a JavaScript hack, meaning that I know enough of the language to make things happen, but not enough to make them happen in the most efficient or effective way. Although the code change below does what you ask, it does not contain any safeguards, browser checks, error handling, etc that all good scripts do. If you intend to use this on a site, I suggest having someone in the Javascript Forum [webmasterworld.com] give pointers on how to make it more stable, secure and efficient.
Nonetheless, swap this out with the script tags in the code block above.
<script type="text/javascript">
function visiblyDisableInput(inputName){
all_inputs = document.getElementsByTagName('input');
for(j=0;j<all_inputs.length;j++){
if(all_inputs[j].className == "meat"){
all_inputs[j].className = "disabled";
}
else if (all_inputs[j].className == "disabled"){
all_inputs[j].className = "meat";
}
}
}
</script>
cEM