I have this working currently, when you press the check box, the drop down (textbox_1) becomes disabled. My question is, how to retrofit this code to also disable textbox_2 by the same click...
<html>
<head>
<script type="text/javascript">
// setup a bit of code to run after the document has loaded. (note that its set on window)
window.addEventListener('load', function(){
potential_checkboxes = document.getElementsByTagName('input');
for(i = 0; i < potential_checkboxes.length; i ++) {
element = potential_checkboxes[i];
// see if we have a checkbox
if (element.getAttribute('type') == 'checkbox') {
// initial setup
textbox = document.getElementById(element.getAttribute('rel'));
textbox.disabled = element.checked;
// add event handler to checkbox
element.addEventListener('change', function() {
// inside here, this refers to the checkbox that just got changed
textbox = document.getElementById(this.getAttribute('rel'));
// set disabled property of textbox to not checked property of this checkbox
textbox.disabled = this.checked;
}, false);
}
}
}, false);
</script>
</head>
<body>
<h1>Enable/disable input based on checkbox.</h1>
<form>
<label for="textbox_1">
<SELECT class="enteredYear" id="textbox_1" name=year>
<OPTION selected value="">Year</OPTION>
<OPTION value=2013>2014</OPTION>
<OPTION value=2013>2013</OPTION>
<OPTION value=2012>2012</OPTION>
</SELECT>
</label>
<label for="textbox_2">
Textbox 1:
<input id="textbox_2" type="text" value="some value" />
</label>
<br />
<input id=="checkbox_1" type="checkbox" rel="textbox_1"/>
<label for="checkbox_1">I have a classic car.</label>
<hr />
<form>
</body>
</html>
relproperty of the checkbox input. So the question is do you care about the ability to specify the target id to be disabled by specifying therelvalue?