Make checkboxes work like radio buttons but...

Discussion in 'Javascript' started by, Jun 23, 2004.

  1. 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

    <input type="checkbox" name="nlbox2" value="8"

    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

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

    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?

    <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.
, Jun 23, 2004
    1. Advertisements


    Lee Guest

    Lee, Jun 23, 2004
    1. Advertisements


    Rob Guest

    Rob, Jun 23, 2004
  4. for (var i = 0; i < 100; i++) {
    document.write("<p>ALWAYS check the FAQ first!<\/p>");

    /L ':p'
    Lasse Reichstein Nielsen, Jun 24, 2004
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.