If statement within For statment keeps getting error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • abbylee26@hotmail.com

    If statement within For statment keeps getting error

    User enters account number
    if another account number is needed
    User clicks add account which creates another row

    When validating when they hit submit I want to check to make sure they tell
    us how much money to charge to all account numbers except the first one (all
    remaining money goes on the first account number)


    within the header script:

    for(i = document.RFO.ar ow.value; i > 1 ; i--){
    if (document.RFO.a cct_tot_i.value ==""){
    alert("Need Amount For Each Account Used");
    document.RFO.ac ct_tot_i.focus( );
    }
    }

    The problem seems to be with the if statement...I'v e also tried
    if (document.RFO.a cct_tot_(i).val ue ==""){
    alert("Need Amount For Each Account Used");
    document.RFO.ac ct_tot_(i).focu s();
    }
  • Michael Winter

    #2
    Re: If statement within For statment keeps getting error

    On Fri, 23 Jan 2004 09:57:13 -0600, <abbylee26@hotm ail.com> wrote:
    [color=blue]
    > for(i = document.RFO.ar ow.value; i > 1 ; i--){
    > if (document.RFO.a cct_tot_i.value ==""){
    > alert("Need Amount For Each Account Used");
    > document.RFO.ac ct_tot_i.focus( );
    > }
    > }
    >
    > The problem seems to be with the if statement...I'v e also tried
    > if (document.RFO.a cct_tot_(i).val ue ==""){
    > alert("Need Amount For Each Account Used");
    > document.RFO.ac ct_tot_(i).focu s();
    > }[/color]

    Try:

    if( '' == document.forms['RFO'].elements['acct_tot_' + i].value ) {
    alert( 'Need amount for each account used.' );
    document.forms['RFO'].elements['acct_tot_' + i].focus();
    }

    The 'if' expression could also be written

    if( !document.forms['RFO'].elements['acct_tot_' + i].value ) {

    Mike

    --
    Michael Winter
    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    • abbylee26@hotmail.com

      #3
      Re: If statement within For statment keeps getting error


      Thanks Michael, but that doesn't work either...it's like my script can't
      detect any account elements except the first one. I've been trying to get
      access to the information for other scripts and can't...the only thing I can
      do is collect the information after the page has been submitted.

      I use the follow script to create text boxes when a person wants to add an

      function addacc(num) {
      var del1 = document.getEle mentById(num)
      var stuff;
      var arow = num * (-1);
      document.RFO.ar ow.value=arow;
      document.all.Ac cAmt.style.visi bility="visible ";
      document.all.Ac cTot.style.visi bility="visible ";
      document.RFO.ac c_tot_1.value=" Balance";
      document.RFO.ac c_tot_1.disable d="true";


      stuff = "<table><tr ><td width=\"70\"><i nput type=\"text\" size=\"5\"
      name=\"fund_" + arow + "\" class=\"regSoft \">"

      stuff = stuff + "</td><td width=\"70\"><i nput type=\"text\" size=\"5\"
      name=\"org_" + arow + "\" class=\"regSoft \">"

      stuff = stuff + "</td><td width=\"70\"><i nput type=\"text\" size=\"5\"
      name=\"program_ " + arow + "\" class=\"regSoft \">"

      stuff = stuff + "</td><td width=\"50\"><i nput type=\"text\" size=\"2\"
      name=\"activity _" + arow + "\" class=\"regSoft \">"

      stuff = stuff + "</td><td width=\"70\">"
      stuff = stuff + "<input name=\"acc_tot_ " + arow + "\" type=\"text\"
      class=\"regSoft \" size=\"5\">"
      stuff = stuff + "</td></tr></table>"

      num = num - 1;

      stuff = stuff + "<div id=\"" + num + "\" style=\"visibil ty:visible\">"
      stuff = stuff + "<A onClick=\"javas cript:addacc(" + num +")\"><u
      class=\"regSoft \"><font color=\"blue\"> Add Account</font></u></a></div>"
      del1.innerHTML = stuff
      }





      Michael Winter <M.Winter@bluey onder.co.invali d> writes:
      [color=blue]
      > On Fri, 23 Jan 2004 09:57:13 -0600, <abbylee26@hotm ail.com> wrote:
      >[color=green]
      > > for(i = document.RFO.ar ow.value; i > 1 ; i--){
      > > if (document.RFO.a cct_tot_i.value ==""){
      > > alert("Need Amount For Each Account Used");
      > > document.RFO.ac ct_tot_i.focus( );
      > > }
      > > }
      > >
      > > The problem seems to be with the if statement...I'v e also tried
      > > if (document.RFO.a cct_tot_(i).val ue ==""){
      > > alert("Need Amount For Each Account Used");
      > > document.RFO.ac ct_tot_(i).focu s();
      > > }[/color]
      >
      > Try:
      >
      > if( '' == document.forms['RFO'].elements['acct_tot_' + i].value ) {
      > alert( 'Need amount for each account used.' );
      > document.forms['RFO'].elements['acct_tot_' + i].focus();
      > }
      >
      > The 'if' expression could also be written
      >
      > if( !document.forms['RFO'].elements['acct_tot_' + i].value ) {
      >
      > Mike
      >[/color]

      Comment

      • Michael Winter

        #4
        Re: If statement within For statment keeps getting error

        On Fri, 23 Jan 2004 11:38:32 -0600, <abbylee26@hotm ail.com> wrote:
        [color=blue]
        > Thanks Michael, but that doesn't work either...it's like my script can't
        > detect any account elements except the first one. I've been trying to get
        > access to the information for other scripts and can't...the only thing I
        > can do is collect the information after the page has been submitted.[/color]

        Could you show an example of the HTML that results from your script? A URL
        would be fine.

        Assuming that acc_tot_n exists in the form RFO,
        document.forms['RFO'].elements['acc_tot_' + n] should work.

        Mike

        --
        Michael Winter
        M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

        Comment

        • abbylee26@hotmail.com

          #5
          Re: If statement within For statment keeps getting error

          Actually, the html only shows the first (hard coded) account text
          boxes...even though you can see them on the web page and they transfer fine,
          the source code shows nothing.
          The first set of text boxes are select option boxes...all additional text
          boxes created are plan text boxes.

          I remember getting to this information once...had to do some strange
          code...but now I forget how I did it.

          after adding a second acct number the source code looks like

          <table>
          <table>
          <tr>
          <td width="70" class="regHard" >Fund</td>
          <td width="70" class="regHard" >Org</td>
          <td width="70" class="regHard" >Program</td>
          <td width="50" class="regHard" >Activity</td>
          <td width="70" class="regHard" ><div id="AccAmt"
          style="visibili ty:hidden">Amou nt</div></td>
          </tr>
          </table>
          <table>
          <tr>
          <td width="70"><sel ect name="fund_1" class="regSoft" >
          <option></option>
          <option>25100 3</option> //500 options deleted
          </select>
          </td>
          <td width="70"><sel ect name="org_1" class="regSoft" >
          <option></option>
          <option>32000 0</option>
          </select>
          </td>
          <td width="70"><sel ect name="program_1 " class="regSoft" >
          <option></option>
          <option>19110 0</option>
          </select>
          </td>
          <td width="50"><sel ect name="activity_ 1" class="regSoft" >
          <option></option>
          <option>A00</option>
          </select>
          </td>
          <td width="70"><div id="AccTot" style="visibili ty:hidden">
          // Hidden until a second account is needed
          <input name="acc_tot_1 " type="text" size="5" class="regSoft" >
          </div>
          </td>
          </tr>
          </table>
          // Create a new account
          </div>
          <div id="-2" style="visibili ty:visible"> <a onClick=javascr ipt:addacc(-2)[color=blue]
          ><u class="regSoft" ><font color="blue">Ad d[/color]
          Account</font></u></a> </div>
          <p>&nbsp;</p>
          <table width="100%" border="0" cellspacing="4" cellpadding="0" >
          <tr>
          <td colspan="2"><in put name="liquor" type="checkbox"
          class="regSoft" value="yes">
          <span class="regHard" >Liquor Purchased?</span></td>
          </tr>
          <tr>
          <td colspan="2"><in put name="deadline" type="checkbox"
          class="regSoft" value="yes">
          <span class="regHard" >Special Deadline?</span> <SPACER> <input
          name="deadline_ date" onBlur="thedead line()" type="text" class="regSoft"
          size="8"></td>
          </tr>
          </table>
          </div>
          </table>

          Michael Winter <M.Winter@bluey onder.co.invali d> writes:
          [color=blue]
          > On Fri, 23 Jan 2004 11:38:32 -0600, <abbylee26@hotm ail.com> wrote:
          >[color=green]
          > > Thanks Michael, but that doesn't work either...it's like my script can't
          > > detect any account elements except the first one. I've been trying to get
          > > access to the information for other scripts and can't...the only thing I
          > > can do is collect the information after the page has been submitted.[/color]
          >
          > Could you show an example of the HTML that results from your script? A URL
          > would be fine.
          >
          > Assuming that acc_tot_n exists in the form RFO,
          > document.forms['RFO'].elements['acc_tot_' + n] should work.
          >
          > Mike
          >[/color]

          Comment

          • abbylee26@hotmail.com

            #6
            Re: If statement within For statment keeps getting error - works now!

            Thanks for your help Michael.

            found something that works....
            "document.RFO.a cct_tot_" + i + ".value == ''"

            Michael Winter <M.Winter@bluey onder.co.invali d> writes:
            [color=blue]
            > On Fri, 23 Jan 2004 11:38:32 -0600, <abbylee26@hotm ail.com> wrote:
            >[color=green]
            > > Thanks Michael, but that doesn't work either...it's like my script can't
            > > detect any account elements except the first one. I've been trying to get
            > > access to the information for other scripts and can't...the only thing I
            > > can do is collect the information after the page has been submitted.[/color]
            >
            > Could you show an example of the HTML that results from your script? A URL
            > would be fine.
            >
            > Assuming that acc_tot_n exists in the form RFO,
            > document.forms['RFO'].elements['acc_tot_' + n] should work.
            >
            > Mike
            >[/color]

            Comment

            • Lasse Reichstein Nielsen

              #7
              Re: If statement within For statment keeps getting error - worksnow!

              abbylee26@hotma il.com writes:
              [color=blue]
              > Michael Winter <M.Winter@bluey onder.co.invali d> writes:[/color]
              [color=blue][color=green]
              >> Assuming that acc_tot_n exists in the form RFO,
              >> document.forms['RFO'].elements['acc_tot_' + n] should work.[/color][/color]
              [color=blue]
              > Thanks for your help Michael.
              >
              > found something that works....
              > "document.RFO.a cct_tot_" + i + ".value == ''"[/color]

              That doesn't work, at least on its own. You then have to use "eval" to
              make it work, which is a *very* bad idea. I suggest you follow
              Michael's advice instead, and forget you ever heard about eval. Your
              code will be better for ir.

              /L 'and please don't top post'
              --
              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

              • abbylee26@hotmail.com

                #8
                Re: If statement within For statment keeps getting error - works now!

                Lasse Reichstein Nielsen <lrn@hotpop.com > writes:
                [color=blue]
                > abbylee26@hotma il.com writes:
                >[color=green]
                > > Michael Winter <M.Winter@bluey onder.co.invali d> writes:[/color]
                >[color=green][color=darkred]
                > >> Assuming that acc_tot_n exists in the form RFO,
                > >> document.forms['RFO'].elements['acc_tot_' + n] should work.[/color][/color]
                >[color=green]
                > > Thanks for your help Michael.
                > >
                > > found something that works....
                > > "document.RFO.a cct_tot_" + i + ".value == ''"[/color]
                >
                > That doesn't work, at least on its own. You then have to use "eval" to
                > make it work, which is a *very* bad idea. I suggest you follow
                > Michael's advice instead, and forget you ever heard about eval. Your
                > code will be better for ir.
                >
                > /L 'and please don't top post'[/color]

                Why, what's wrong with using eval...seems to be working fine.

                Comment

                • Lasse Reichstein Nielsen

                  #9
                  Re: If statement within For statment keeps getting error - worksnow!

                  abbylee26@hotma il.com writes:
                  [color=blue]
                  > Why, what's wrong with using eval...seems to be working fine.[/color]

                  The FAQ says:
                  <URL:http://jibbering.com/faq/#FAQ4_40>
                  The reason is that eval
                  1) inefficient (very)
                  2) failure prone - syntax errors are not caught when the program is
                  parsed like normally, but only when the eval is run, which makes it
                  harder to spot errors and debug them
                  3) so easy to avoid by using the normal language constructs, that
                  there is no positive reason to use it that can outweigh the above two.

                  /L
                  --
                  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...