syntax error

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

    syntax error

    Hello,

    The line below is OK

    document.write( "<td ID='fred' >" + this.lhs_0[1] + "</td>");

    but how do I write the more general version where the 0 is
    situation_numbe r and the 1 is count - ie 2 variables?

    ie I know the following is wrong!

    document.write( "<td ID='fred' >" + "this.lhs_" + situation_numbe r +
    "[" + count +"1" + "</td>");

    How should it be written?

    Thanks

    Geoff






  • Mick White

    #2
    Re: syntax error

    Geoff Cox wrote:[color=blue]
    > Hello,
    >
    > The line below is OK
    >
    > document.write( "<td ID='fred' >" + this.lhs_0[1] + "</td>");
    >
    > but how do I write the more general version where the 0 is
    > situation_numbe r and the 1 is count - ie 2 variables?
    >
    > ie I know the following is wrong!
    >
    > document.write( "<td ID='fred' >" + "this.lhs_" + situation_numbe r +
    > "[" + count +"1" + ;
    >
    > How should it be written?
    >[/color]

    <td ID='fred' >"+
    window["lhs_" + situation_numbe r][count++]+
    "</td>"
    Something like that, if "count" is to be incremented and lhs_0 ... _n
    series are global variables.
    Mick

    Mick

    Comment

    • ASM

      #3
      Re: syntax error

      Geoff Cox wrote:[color=blue]
      > Hello,
      >
      > The line below is OK
      >
      > document.write( "<td ID='fred' >" + this.lhs_0[1] + "</td>");
      >
      > but how do I write the more general version where the 0 is
      > situation_numbe r and the 1 is count - ie 2 variables?
      >
      > ie I know the following is wrong!
      >
      > document.write( "<td ID='fred' >" + "this.lhs_" + situation_numbe r +
      > "[" + count +"1" + "</td>");
      >
      > How should it be written?[/color]

      I don't know ...

      document.write( "<td ID='fred' >" + this['lhs_'situation _number[1]] +
      "<\/td>");

      or

      document.write( "<td ID='fred' >" +
      eval('this.lhs_ '+situation_num ber+'[1]') + "<\/td>");

      --
      Stephane Moriaux et son [moins] vieux Mac

      Comment

      • Geoff Cox

        #4
        Re: syntax error

        On Mon, 12 Sep 2005 15:18:03 GMT, Mick White
        <mwhite13BOGUS@ rochester.rr.co m> wrote:
        [color=blue]
        ><td ID='fred' >"+
        >window["lhs_" + situation_numbe r][count++]+
        >"</td>"[/color]

        Mick,

        Thanks for the above - it works fine but am the following does not
        work. Can you explain why for me please then I might grasp why the
        first one does work!

        Cheers

        Geoff

        document.getEle mentById('fred' ).innerHTML = window["lhs_"
        + situation_numbe r][count];

        Comment

        • Mick White

          #5
          Re: syntax error

          Geoff Cox wrote:
          [color=blue]
          > On Mon, 12 Sep 2005 15:18:03 GMT, Mick White
          > <mwhite13BOGUS@ rochester.rr.co m> wrote:
          >
          >[color=green]
          >><td ID='fred' >"+
          >>window["lhs_" + situation_numbe r][count++]+
          >>"</td>"[/color]
          >
          >
          > Mick,
          >
          > Thanks for the above - it works fine but am the following does not
          > work. Can you explain why for me please then I might grasp why the
          > first one does work!
          >
          > Cheers
          >
          > Geoff
          >
          > document.getEle mentById('fred' ).innerHTML = window["lhs_"
          > + situation_numbe r][count];
          >[/color]

          Try:
          alert(count)
          alert(window["lhs_" + situation_numbe r][count])


          Mick


          Comment

          • Geoff Cox

            #6
            Re: syntax error

            On Mon, 12 Sep 2005 16:16:48 GMT, Mick White
            <mwhite13BOGUS@ rochester.rr.co m> wrote:
            [color=blue][color=green]
            >> document.getEle mentById('fred' ).innerHTML = window["lhs_"
            >> + situation_numbe r][count];
            >>[/color]
            >
            >Try:
            >alert(count)
            >alert(window["lhs_" + situation_numbe r][count])[/color]

            Mick,

            trying above I get

            1. the alert window with the correct value of teh count variable and
            the array value for lhs_0[1] displayed on a new page.

            2. I click on the alert OK and get error message

            'window[...]' is null or not an object

            Thoughts?

            Geoff

            Comment

            • Geoff Cox

              #7
              Re: syntax error

              On Mon, 12 Sep 2005 16:16:48 GMT, Mick White
              <mwhite13BOGUS@ rochester.rr.co m> wrote:
              [color=blue]
              >Geoff Cox wrote:
              >[color=green]
              >> On Mon, 12 Sep 2005 15:18:03 GMT, Mick White
              >> <mwhite13BOGUS@ rochester.rr.co m> wrote:
              >>
              >>[color=darkred]
              >>><td ID='fred' >"+
              >>>window["lhs_" + situation_numbe r][count++]+
              >>>"</td>"[/color]
              >>
              >>
              >> Mick,
              >>
              >> Thanks for the above - it works fine but am the following does not
              >> work. Can you explain why for me please then I might grasp why the
              >> first one does work![/color][/color]

              Mick

              Oops! my mistake - some other code left in.

              Cheers

              Gepff[color=blue][color=green]
              >>
              >> Cheers
              >>
              >> Geoff
              >>
              >> document.getEle mentById('fred' ).innerHTML = window["lhs_"
              >> + situation_numbe r][count];
              >>[/color]
              >
              >Try:
              >alert(count)
              >alert(window["lhs_" + situation_numbe r][count])
              >
              >
              >Mick
              >[/color]

              Comment

              Working...