Make checkboxes work like radio buttons but...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shortbackandsides.no@spam.hairdresser.net

    #1

    Make checkboxes work like radio buttons but...

    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="docume nt.signup.nlbox 2.checked=!docu ment.signup.nlb ox2.checked;">

    <input type="checkbox" name="nlbox2" value="8"
    onClick="docume nt.signup.nlbox 1.checked=!docu ment.signup.nlb ox1.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="docume nt.signup.nlbox[2].checked=!docum ent.signup.nlbo x[2].checked;">

    <input type="checkbox" name="nlbox[2]" value="8"
    onClick="docume nt.signup.nlbox[1].checked=!docum ent.signup.nlbo x[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.

  • Lee

    #2
    Re: Make checkboxes work like radio buttons but...

    shortbackandsid es.no@spam.hair dresser.net said:
    [color=blue]
    >The problem is if I try to use:
    >
    ><input type="checkbox" name="nlbox[1]" value="9" checked
    >onClick="docum ent.signup.nlbo x[2].checked=!docum ent.signup.nlbo x[2].checked;">
    >
    ><input type="checkbox" name="nlbox[2]" value="8"
    >onClick="docum ent.signup.nlbo x[1].checked=!docum ent.signup.nlbo x[1].checked;">
    >
    >I get an error. Mozilla says:
    >document.signu p.nlbox has no properties
    >
    >MSIE says:
    >document.signu p.nlbox.1 is null or not an object
    >
    >Any ideas?[/color]




    Comment

    • Rob

      #3
      Re: Make checkboxes work like radio buttons but...

      On 23 Jun 2004 13:31:31 -0700, Lee <REM0VElbspamtr ap@cox.net> wrote:
      [color=blue][color=green]
      >>
      >>MSIE says:
      >>document.sign up.nlbox.1 is null or not an object
      >>
      >>Any ideas?[/color]
      >
      >
      >http://www.jibbering.com/faq/#FAQ4_25[/color]

      Excellent, thanks it works just fine now.

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

      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: Make checkboxes work like radio buttons but...

        Rob <public.mail@sh effield.port995 .com> writes:
        [color=blue]
        > I'll just go and write out 100 times "ALWAYS check the FAQ first!"[/color]

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

        /L ':P'
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        Working...