Step 1: Give your element IDs so that you can work with them via javascript
Step 2: Attach an "onchange" event to checkbox
Step 3: Use the value of "this.checked" to find out whether the checkbox is on/off
Step 4: Use that value to enable / disable the other elements
RESULT:
- Code: Select all
<form action="" method="">
<textarea name="Textarea1" id="Textarea1" cols="40" rows="5"></textarea>
<input type="radio" name="radio1" id="radio1" value="show">
<input type="Checkbox" name="Delete1" id="Delete1" onchange="
document.getElementById('Textarea1').disabled = this.checked;
document.getElementById('radio1').disabled = this.checked;
" value="123">
</form>
ALTERNATIVE:
If you're starting up, I suggest you familiarize yourself with a library that takes care of browser compatibility for you. It can be very frustrating having to deal with these issues as an experienced developer - even more infuriating if you're a beginner.
Step 1: Give your element IDs so that you can work with them via javascript
Step 2: Get
jQuery
Step 3: Use this code
- Code: Select all
<form action="" method="">
<textarea name="Textarea1" id="Textarea1" cols="40" rows="5"></textarea>
<input type="radio" name="radio1" id="radio1" value="show">
<input type="Checkbox" name="Delete1" id="Delete1" value="123">
</form>
<script language="javascript">
$(function(){
$('#Delete1').change(function(){
$('#Textarea1, #radio1').attr('disabled', this.checked);
});
});
</script>
Techie note:
I'm sorry if I seem to be pushing everyone towards jQuery, but with a few years of experience, countless nights and cups of coffee under my belt, I think jQuery is the easiest way to introduce a beginner to jQuery - taking away the worries of cross browser compatibility.