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>

Ignore this post, (Network Error!)...

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 :).

If you need more info about <label></label> tag, please visit this LINK.

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!

Try to upload your html document in ASCII mode.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.