Hi all,
Say there are two checkboxes on a page (test1 and test2), I want to write a JavaScript code that disables one if the other is checked. Here's what I wrote that didn't work:

<input type="checkbox" name="test1" <script language="Javascript">if (test2.checked = true){document.write('DISABLED');}</script>>

Please help :D!!! Thanks a million!

Jeff

Do it this way:

<html>
<head>
<title>Your title</title>
</head>
<body>
<div>
<form action="#" onsubmit="return false;">
<div>
<label>Item 1 <input type="checkbox" id="ch0" name="ch0" value="" onclick="if (this.checked) document.getElementById('ch1').disabled=true; else document.getElementById('ch1').disabled = false;"  /></label><br />
<label>Item 2 <input type="checkbox" id="ch1" name="ch1" value="" onclick="if (this.checked) document.getElementById('ch0').disabled=true; else document.getElementById('ch0').disabled = false;" /></label>
</div>
</form>
</div>
</body>
</html>

Thank you VERY much I will try it out in the morning!

Just curious, what is this <LABEL> tag and is it necessary? I have never seen it before :).

Strangest thing: it works beautifully in my editor's preview window but when I upload it to my site it doesn't???

Any ideas? Thanks :D!

EDIT: Turns out the ID value is absolutely necessary!

This article has been dead for over six months. Start a new discussion instead.