Using variables in [document.VARIABLE.VARIABLE.checked], etc...

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

    Using variables in [document.VARIABLE.VARIABLE.checked], etc...

    I would like to use variables in...

    for(q = 0; q < i; q++) {
    if(document.var Array1[q].varArray2[q].checked == TRUE) {
    alert("YES");
    }
    else {
    alert("NO");
    }
    }

    What's the proper syntax?

    --
    [ Sugapablo ]
    [ http://www.sugapablo.com <--music ]
    [ http://www.sugapablo.net <--personal ]
    [ sugapablo@12jab ber.com <--jabber IM ]

  • Lee

    #2
    Re: Using variables in [document.VARIAB LE.VARIABLE.che cked], etc...

    Sugapablo said:[color=blue]
    >
    >I would like to use variables in...
    >
    > for(q = 0; q < i; q++) {
    > if(document.var Array1[q].varArray2[q].checked == TRUE) {
    > alert("YES");
    > }
    > else {
    > alert("NO");
    > }
    > }
    >
    >What's the proper syntax?[/color]

    Assuming that the variables represent the name of a form and
    the name of an element in that form, respectively:

    if(document.for ms[varArray1[q]].elements[varArray2[q]].checked)

    Note that there's no need to compare a boolean to true.
    Its own value will always be the value of the comparison.

    Comment

    • Ivo

      #3
      Re: Using variables in [document.VARIAB LE.VARIABLE.che cked], etc...

      "Lee" wrote:[color=blue]
      > Sugapablo said:[color=green]
      > >
      > >I would like to use variables in...
      > >
      > > for(q = 0; q < i; q++) {
      > > if(document.var Array1[q].varArray2[q].checked == TRUE) {
      > > alert("YES");
      > > }
      > > else {
      > > alert("NO");
      > > }
      > > }
      > >
      > >What's the proper syntax?[/color]
      >
      > Assuming that the variables represent the name of a form and
      > the name of an element in that form, respectively:
      >
      > if(document.for ms[varArray1[q]].elements[varArray2[q]].checked)
      >
      > Note that there's no need to compare a boolean to true.
      > Its own value will always be the value of the comparison.[/color]

      This loop will only check the first element in the first form, the second in
      the second and the third in the third. If you want to check all items in all
      forms, you need to nest two loops.
      Also see this naming issue addressed in the FAQ:
      <URL: http://jibbering.com/faq/#FAQ4_39 >

      HTH
      Ivo


      Comment

      • Dr John Stockton

        #4
        Re: Using variables in [document.VARIAB LE.VARIABLE.che cked], etc...

        JRS: In article <cc1itl01d9b@dr n.newsguy.com>, seen in
        news:comp.lang. javascript, Lee <REM0VElbspamtr ap@cox.net> posted at Thu,
        1 Jul 2004 10:50:45 :[color=blue]
        >Sugapablo said:[/color]
        [color=blue][color=green]
        >> if(document.var Array1[q].varArray2[q].checked == TRUE) {[/color][/color]
        [color=blue]
        >Note that there's no need to compare a boolean to true.
        >Its own value will always be the value of the comparison.[/color]


        ISTM that he's not comparing it to true, but to TRUE, which is a
        variable, possibly defined. In principle, it could be defined as
        TRUE = !!Math.round(Ma th.random())

        It is == true that he should not be using, not == TRUE .

        --
        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
        Web <URL:http://www.merlyn.demo n.co.uk/> - FAQish topics, acronyms, & links.
        Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
        Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

        Comment

        Working...