Make checkboxes work like radio buttons but...

  • Thread starter shortbackandsides.no
  • Start date
S

shortbackandsides.no

Here's a working code fragment out of a form.
One checkbox is checked the other isn't.
When you change the status of one the other changes too.

<input type="checkbox" name="nlbox1" value="9" checked
onClick="document.signup.nlbox2.checked=!document.signup.nlbox2.checked;">

<input type="checkbox" name="nlbox2" value="8"
onClick="document.signup.nlbox1.checked=!document.signup.nlbox1.checked;">

OK now the problem (and I expect you are asking, why not just use
radio buttons?)

The form gets sent to someone else's script on a server I can't
modify. Their version of the form looked like this:

<input type="checkbox" name="nlbox[1]" value="9" >
<input type="checkbox" name="nlbox[2]" value="8">

That allowed neither or both boxes to be checked. The problem is if I
try to use:

<input type="checkbox" name="nlbox[1]" value="9" checked
onClick="document.signup.nlbox[2].checked=!document.signup.nlbox[2].checked;">

<input type="checkbox" name="nlbox[2]" value="8"
onClick="document.signup.nlbox[1].checked=!document.signup.nlbox[1].checked;">

I get an error. Mozilla says:
document.signup.nlbox has no properties

MSIE says:
document.signup.nlbox.1 is null or not an object

Any ideas?

Incidentally
<input type="radio" name="nlbox[1]" value="9" >
<input type="radio" name="nlbox[2]" value="8">
won't work because as the name differs they don't operate as a pair.
 
L

Lee

(e-mail address removed) said:
The problem is if I try to use:

<input type="checkbox" name="nlbox[1]" value="9" checked
onClick="document.signup.nlbox[2].checked=!document.signup.nlbox[2].checked;">

<input type="checkbox" name="nlbox[2]" value="8"
onClick="document.signup.nlbox[1].checked=!document.signup.nlbox[1].checked;">

I get an error. Mozilla says:
document.signup.nlbox has no properties

MSIE says:
document.signup.nlbox.1 is null or not an object

Any ideas?


http://www.jibbering.com/faq/#FAQ4_25
 
L

Lasse Reichstein Nielsen

Rob said:
I'll just go and write out 100 times "ALWAYS check the FAQ first!"

for (var i = 0; i < 100; i++) {
document.write("<p>ALWAYS check the FAQ first!<\/p>");
}

/L ':p'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top