Syntax help please

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ed Jay

    Syntax help please

    I'm trying to put:

    document.form1. proto0[0].checked=true;
    document.form1. proto1[0].checked = true;
    document.form1. proto2[0].checked = true;
    ..
    ..
    document.form1. proton[0].checked =true;

    into a loop. I've unsuccessfully tried:

    for (var i=0;i<n+1;i++) {
    document.form1. proto+i+[0].checked=true;
    }

    and I've been unsuccessful using:

    for (var i=0;i<n+1;i++) {
    document.forms["form1"].elements["proto"+i+"[0]"].checked=true;
    }

    Syntax-wise, where am I going astray?

    --
    Ed Jay (remove 'M' to reply by email)

    Win the War Against Breast Cancer.
    Knowing the facts could save your life.

  • Lasse Reichstein Nielsen

    #2
    Re: Syntax help please

    Ed Jay <edMbj@aes-intl.comwrites:
    I'm trying to put:
    >
    document.form1. proto0[0].checked=true;
    document.form1. proto1[0].checked = true;
    document.form1. proto2[0].checked = true;
    .
    .
    document.form1. proton[0].checked =true;
    >
    into a loop.
    Smart move. :)

    ....
    and I've been unsuccessful using:
    >
    for (var i=0;i<n+1;i++) {
    document.forms["form1"].elements["proto"+i+"[0]"].checked=true;
    This was close!
    }
    >
    Syntax-wise, where am I going astray?
    The [0] is not part of the name. The name is "proto2", and there
    are apparently more elements in the form with that name.
    Try:

    var elems = document.form["form1"].elements;
    for(var i = 0; i < n; i++) {
    elems["proto"+i][0].checked = true;
    }

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

    Comment

    • Evertjan.

      #3
      Re: Syntax help please

      Ed Jay wrote on 06 sep 2008 in comp.lang.javas cript:
      document.forms["form1"].elements["proto"+i+"[0]"].checked=true;
      Methinks:

      document.forms["form1"].elements["proto"+i][0].checked=true;

      [If these are radio buttons]


      --
      Evertjan.
      The Netherlands.
      (Please change the x'es to dots in my emailaddress)

      Comment

      • Ed Jay

        #4
        Re: Syntax help please

        Evertjan. wrote:
        >Ed Jay wrote on 06 sep 2008 in comp.lang.javas cript:
        >
        >document.for ms["form1"].elements["proto"+i+"[0]"].checked=true;
        >
        >Methinks:
        >
        >document.for ms["form1"].elements["proto"+i][0].checked=true;
        >
        >[If these are radio buttons]
        They are, indeed. I have several rows of two buttons each that I'm setting
        if a preceding condition is met.

        --
        Ed Jay (remove 'M' to reply by email)

        Win the War Against Breast Cancer.
        Knowing the facts could save your life.

        Comment

        • Ed Jay

          #5
          Re: Syntax help please

          Lasse Reichstein Nielsen wrote:
          >Ed Jay <edMbj@aes-intl.comwrites:
          >
          >I'm trying to put:
          >>
          >document.form1 .proto0[0].checked=true;
          >document.form1 .proto1[0].checked = true;
          >document.form1 .proto2[0].checked = true;
          >>
          >into a loop.
          >
          >and I've been unsuccessful using:
          >>
          >for (var i=0;i<n+1;i++) {
          >document.for ms["form1"].elements["proto"+i+"[0]"].checked=true;
          >>}
          >
          >Syntax-wise, where am I going astray?
          >
          >The [0] is not part of the name. The name is "proto2", and there
          >are apparently more elements in the form with that name.
          >Try:
          >
          var elems = document.form["form1"].elements;
          for(var i = 0; i < n; i++) {
          elems["proto"+i][0].checked = true;
          }
          >
          Thanks, but it's not working. I continue to receive an error msg:
          "Cannot convert undefined or null to Object." (The original multi-line,
          non-loop command works fine.)

          By way of elaboration, this issue pertains to multiple rows of radio button
          pairs that I'm setting pursuant to a previous condition being met, e.g.,.
          proto0[0] and proto0[1], etc.

          --
          Ed Jay (remove 'M' to reply by email)

          Win the War Against Breast Cancer.
          Knowing the facts could save your life.

          Comment

          • Gregor Kofler

            #6
            Re: Syntax help please

            Ed Jay meinte:
            Lasse Reichstein Nielsen wrote:
            >var elems = document.form["form1"].elements;
            ^^^^
            Typo - should be document.forms[...]

            Gregor


            --
            http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
            http://web.gregorkofler.com ::: meine JS-Spielwiese
            http://www.image2d.com ::: Bildagentur für den alpinen Raum

            Comment

            • Ed Jay

              #7
              Re: Syntax help please

              Gregor Kofler wrote:
              >Ed Jay meinte:
              >
              >Lasse Reichstein Nielsen wrote:
              >
              >>var elems = document.form["form1"].elements;
              ^^^^
              >Typo - should be document.forms[...]
              >
              Teach me to cut and paste! :-)

              Works.

              --
              Ed Jay (remove 'M' to reply by email)

              Win the War Against Breast Cancer.
              Knowing the facts could save your life.

              Comment

              • Ed Jay

                #8
                Re: Syntax help please

                Ed Jay wrote:
                >Lasse Reichstein Nielsen wrote:
                >
                >>Ed Jay <edMbj@aes-intl.comwrites:
                >>
                >>I'm trying to put:
                >>>
                >>document.form 1.proto0[0].checked=true;
                >>document.form 1.proto1[0].checked = true;
                >>document.form 1.proto2[0].checked = true;
                >>>
                >>into a loop.
                >>
                >>and I've been unsuccessful using:
                >>>
                >>for (var i=0;i<n+1;i++) {
                >>document.form s["form1"].elements["proto"+i+"[0]"].checked=true;
                >>>}
                >>
                >>Syntax-wise, where am I going astray?
                >>
                >>The [0] is not part of the name. The name is "proto2", and there
                >>are apparently more elements in the form with that name.
                >>Try:
                >>
                >var elems = document.form["form1"].elements;
                >for(var i = 0; i < n; i++) {
                > elems["proto"+i][0].checked = true;
                >}
                >>
                >Thanks, but it's not working. I continue to receive an error msg:
                >"Cannot convert undefined or null to Object." (The original multi-line,
                >non-loop command works fine.)
                >
                >By way of elaboration, this issue pertains to multiple rows of radio button
                >pairs that I'm setting pursuant to a previous condition being met, e.g.,.
                >proto0[0] and proto0[1], etc.
                Now that Gregor Kofler has pointed out the typo, it works great. Thanks,
                Lasse.

                --
                Ed Jay (remove 'M' to reply by email)

                Win the War Against Breast Cancer.
                Knowing the facts could save your life.

                Comment

                Working...