Form validation - undefined field

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

    Form validation - undefined field

    I am trying to reference a table entry (qtyonhand) populated from a
    recordset. There is only one record displayed on this table. When i try to
    compare this displayed field to an input field (orderqty) i get an (error on
    this page or no result at all ). When just comparing the input field to a
    set of "" everything works fine. This is an ASP file with a javascript
    function. Thanks in advance.

    Signed... New at this!

    code below...
    ----------------------------------------------------------
    <SCRIPT LANGUAGE="JavaS cript" TYPE="text/javascript">
    function btnValidate_onc lick()
    {
    var myform = document.form1;
    var qtyonhand = myform.qtyonhan d.value;
    alert( myform.orderqty .value + " ");
    if(myform.order qty.value=='' || myform.orderqty .value > qtyonhand)

    {alert(" Qty ordered is missing or greater than Qty on hand. ");
    myform.orderqty .focus();
    }
    }
    </SCRIPT>




  • Lee

    #2
    Re: Form validation - undefined field

    tm said:[color=blue]
    >
    >I am trying to reference a table entry (qtyonhand) populated from a
    >recordset. There is only one record displayed on this table. When i try to
    >compare this displayed field to an input field (orderqty) i get an (error on
    >this page or no result at all ). When just comparing the input field to a
    >set of "" everything works fine. This is an ASP file with a javascript
    >function. Thanks in advance.
    >
    >Signed... New at this!
    >
    >code below...
    >----------------------------------------------------------
    > <SCRIPT LANGUAGE="JavaS cript" TYPE="text/javascript">
    >function btnValidate_onc lick()
    >{
    > var myform = document.form1;
    > var qtyonhand = myform.qtyonhan d.value;[/color]

    You say that qtyonhand is a "table entry".
    That's not a very precise description.
    Is it a form field?
    Maybe you need to show the relevant HTML.

    Comment

    • tm

      #3
      Re: Form validation - undefined field

      The field qtyonhand is a form field displayed within the table, sorry
      for the confusion.

      Relevant HTML.
      -------------------------------------------------------
      <form method="post" action="CustOrd er06.asp" name=form1>

      <table width="600" border="0" align="center">
      <tr>
      <td width="640"><di v align="center" class="ms-separator"><fon t
      face=Arial size=4>Storage and Moving Company </font></div></td>
      </tr>
      <tr>
      <td><div align="center" class="style5"> <FONT face="Arial"
      size="3">Custom er Order Entry Page</FONT></div></td>
      </tr>
      <tr>
      <td><div align="center" class="style5"> <FONT face=Arial><spa n
      class="style10" ><span class="style11" >
      <% Response.Write( cusnam)%>
      </span></span> </FONT></div></td>
      </tr>
      </table>
      <div align="center" class="style10" >
      <p>&nbsp;</p>
      <p>Enter your order amount below. </p>
      </div>
      <div align="center" class="style10" ></div>
      <div align="center">
      <TABLE width="600" class="ms-caldow">
      <!--DWLayoutTable-->
      <TR>
      <TH WIDTH="150" height="56" ALIGN=middle> <P
      align=left><STR ONG><FONT size="2" face=Tahoma> Item Number
      </FONT></STRONG></P></TH>
      <TH ALIGN=middle WIDTH="250"> <P align=left><STR ONG><FONT size="2"
      face=Tahoma> Description</FONT></STRONG></P></TH>
      <TH ALIGN=middle WIDTH="100"> <P><STRONG><FON T size="2"
      face=Tahoma>Ent er Order Amount </FONT></STRONG></P></TH>
      <TH ALIGN=middle WIDTH="100"> <div align="center"> <font size="2"
      face="Tahoma">Q ty Available </font></div></TH>
      </TR>
      <%
      Do While Not rstINMST.EOF
      %>
      <TR>
      <TD BGCOLOR="#FFFFF F" ALIGN=middle><P align=left>
      <FONT SIZE=2[color=blue]
      >[/color]
      <div align="left">
      <% =rstINMST("ITMN UM") %>
      </A> </div></TD>
      <TD BGCOLOR="#FFFFF F" align=middle><d iv align="left"><F ONT SIZE=2[color=blue]
      >[/color]
      <%
      Response.Write rstINMST("ITMDE SC")
      %>
      </FONT> </div></TD>
      <TD BGCOLOR="#FFFFF F" ALIGN=right>
      <FONT SIZE=2[color=blue]
      >[/color]
      <input name="orderqty" id="orderqty" size="13" maxlength="7">
      <TD BGCOLOR="#FFFFC C" ALIGN=middle><d iv align="right">< FONT SIZE=2[color=blue]
      >[/color]
      <%
      Response.Write FormatNumber(rs tINMST("qtyonha nd"),0)
      qtyoh = rstINMST("qtyon hand")
      %>
      <STRONG><FONT face="Trebuchet MS"><FONT
      style="BACKGROU ND-COLOR:
      #ffffff"></FONT></STRONG></FONT></div></TD>
      </TR>
      <%
      rstINMST.movene xt
      loop
      %>
      </TABLE>

      </div>
      <p align="center"> <span class="style10" ><span class="style2">
      <input type="button" name="btnValida te" value="Validate "
      onclick="btnVal idate_onclick() ">
      <input name="Submit" type="submit" value="Continue ">
      </span></span></p>
      <p><strong>

      <%
      rstINMST.Close
      set rstINMST=Nothin g
      conINMST.Close
      set conINMST=Nothin g
      %>
      </strong></P>
      </body>
      </html>




      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Lee

        #4
        Re: Form validation - undefined field

        tm said:[color=blue]
        >
        >The field qtyonhand is a form field displayed within the table, sorry
        >for the confusion.
        >
        >Relevant HTML.[/color]

        This seems to be the only occurance of "qtyonhand" .
        It's not HTML or Javascript, so I don't know for sure
        that it's creating a form element by that name.

        <%
        Response.Write FormatNumber(rs tINMST("qtyonha nd"),0)
        qtyoh = rstINMST("qtyon hand")
        %>

        Comment

        • kaeli

          #5
          Re: Form validation - undefined field

          In article <415c6660$1@new s.lh.net>, tommertz@hotmai l.com enlightened us
          with...[color=blue]
          > I am trying to reference a table entry (qtyonhand) populated from a
          > recordset. There is only one record displayed on this table. When i try to
          > compare this displayed field to an input field (orderqty) i get an (error on
          > this page or no result at all ). When just comparing the input field to a
          > set of "" everything works fine. This is an ASP file with a javascript
          > function. Thanks in advance.
          >
          > Signed... New at this!
          >
          > code below...[/color]

          To see problems with the javascript, your best bet is to look at the actual
          source that the browser sees - the View Source of the browser. NOT the ASP
          code you used to generate it.

          It's possible that the ASP isn't writing what you expect it to (the fields
          aren't there at all).
          Post the source from the view source if the following doesn't fix the
          problem.

          I fixed the following to be more cross-browser instead of using shortcut
          syntax. That includes making the variable names different from the names in
          the form, JIC. I also used parseInt to make sure the values are used as
          numbers, not text. I put in checks for the form fields for your testing
          purposes. They can be removed for production.

          <SCRIPT LANGUAGE="JavaS cript" TYPE="text/javascript">
          function btnValidate_onc lick()
          {
          if (! document.forms["form1"].elements["qtyonhand"])
          {
          alert("Form field missing: qtyonhand");
          return false;
          }

          if (! document.forms["form1"].elements["orderqty"])
          {
          alert("Form field missing: orderqty");
          return false;
          }

          var v_qtyonhand = parseInt(docume nt.forms["form1"].elements
          ["qtyonhand"].value,10);
          var v_orderqty = parseInt(docume nt.forms["form1"].elements
          ["orderqty"].value,10);

          if (isNaN(v_qtyonh and) || isNaN(v_orderqt y))
          {
          alert("Not a number!");
          return false;
          }

          if(v_orderqty == 0 || v_orderqty > qtyonhand)
          {
          alert(" Qty ordered is missing or greater than Qty on hand. ");
          document.forms["form1"].elements["orderqty"].focus();
          }
          }
          </SCRIPT>

          This is untested. Watch for word-wrapping.
          HTH

          --
          --
          ~kaeli~
          No one is listening until you make a mistake.



          Comment

          • tm

            #6
            Re: Form validation - undefined field

            Thanks for cleaning up the code.
            The javascript does indicate that the qtyonhand field is missing. I know
            i am missing something here.
            Got to go thru the learning curve. Thanks for your help.
            view source posted below.
            --------------------------------------------------------
            <!-- Validated at 10/1/2004 9:38:40 AM -->
            <html>
            <head>
            <title>Custom er Deliver Order Item Detail</title>
            <style type="text/css">
            <!--
            .style3 {font-size: xx-small}
            .style4 {font-size: xx-small; color: #0000FF; }
            .style5 {
            color: #000000;
            font-weight: bold;
            }
            -->
            </style>
            <style type="text/css">
            <!--
            .style10 {color: #FF0000}
            .style11 {color: #FF0000; font-weight: bold; }
            -->
            </style>
            <!--mstheme-->
            <link rel="stylesheet " type="text/css"
            href="_themes/blitz/blit1111.css">
            <meta name="Microsoft Theme" content="blitz 1111">
            <style type="text/css">
            <!--
            .style13 {color: #0000FF}
            -->
            </style>
            </head>
            <body>

            <form method="post" action="CustOrd er06.asp" name=form1>

            <table width="600" border="0" align="center">
            <tr>
            <td width="640"><di v align="center" class="ms-separator"><fon t
            face=Arial size=4>Ford Storage and Moving Company </font></div></td>
            </tr>
            <tr>
            <td><div align="center" class="style5"> <FONT face="Arial"
            size="3">Custom er Order Entry Page</FONT></div></td>
            </tr>
            <tr>
            <td><div align="center" class="style5"> <FONT face=Arial><spa n
            class="style10" ><span class="style11" >
            ENTERPRISE GROUP
            </span></span> </FONT></div></td>
            </tr>
            </table>
            <div align="center" class="style10" >
            <p>&nbsp;</p>
            <p>Enter your order amount below. </p>
            </div>
            <div align="center" class="style10" ></div>
            <div align="center">
            <TABLE width="600" class="ms-caldow">
            <!--DWLayoutTable-->
            <TR>
            <TH WIDTH="150" height="56" ALIGN=middle> <P
            align=left><STR ONG><FONT size="2" face=Tahoma> Item Number
            </FONT></STRONG></P></TH>
            <TH ALIGN=middle WIDTH="250"> <P align=left><STR ONG><FONT size="2"
            face=Tahoma> Description</FONT></STRONG></P></TH>
            <TH ALIGN=middle WIDTH="100"> <P><STRONG><FON T size="2"
            face=Tahoma>Ent er Order Amount </FONT></STRONG></P></TH>
            <TH ALIGN=middle WIDTH="100"> <div align="center"> <font size="2"
            face="Tahoma">Q ty Available </font></div></TH>
            </TR>

            <TR>
            <TD BGCOLOR="#FFFFF F" ALIGN=middle><P align=left>
            <FONT SIZE=2[color=blue]
            >[/color]
            <div align="left">
            EGIJB24-4
            </A> </div></TD>
            <TD BGCOLOR="#FFFFF F" align=middle><d iv align="left"><F ONT SIZE=2[color=blue]
            >[/color]
            24 X INK JET ROLL
            </FONT> </div></TD>
            <TD BGCOLOR="#FFFFF F" ALIGN=right>
            <FONT SIZE=2[color=blue]
            >[/color]
            <input name="orderqty" id="orderqty" size="13" maxlength="7">
            <TD BGCOLOR="#FFFFC C" ALIGN=middle><d iv align="right">< FONT SIZE=2[color=blue]
            >[/color]
            3
            <STRONG><FONT face="Trebuchet MS"><FONT
            style="BACKGROU ND-COLOR:
            #ffffff"></FONT></STRONG></FONT></div></TD>
            </TR>

            </TABLE>

            </div>
            <p align="center"> <span class="style10" ><span class="style2">
            <input type="button" name="btnValida te" value="Validate "
            onclick="btnVal idate_onclick() ">
            <input name="Submit" type="submit" value="Continue ">
            </span></span></p>
            <p><strong>


            </strong></P>
            <table width="364" border="0">
            <tr>
            <td width="172"><sp an class="style3"> For technical questions email
            </span></td>
            <td width="176"><a href="mailto:we bmaster@fordsto rage.com"
            class="style4"> Web Development </a></td>
            </tr>
            <tr>
            <td><span class="style3"> For questions concerning
            balances</span></td>
            <td><a href="mailto:bs chramm@fordstor age.com" class="style4"> Becky
            Schramm</a></td>
            </tr>
            </table>
            </body>
            </html>

            <SCRIPT LANGUAGE="JavaS cript" TYPE="text/javascript">
            function btnValidate_onc lick()
            {
            if (! document.forms["form1"].elements["qtyonhand"])
            {
            alert("Form field missing: qtyonhand");
            return false;
            }

            if (! document.forms["form1"].elements["orderqty"])
            {
            alert("Form field missing: orderqty");
            return false;
            }

            var v_qtyonhand = parseInt(docume nt.forms["form1"].elements
            ["qtyonhand"].value,10);
            var v_orderqty = parseInt(docume nt.forms["form1"].elements
            ["orderqty"].value,10);

            if (isNaN(v_qtyonh and) || isNaN(v_orderqt y))
            {
            alert("Not a number!");
            return false;
            }

            if(v_orderqty == 0 || v_orderqty > qtyonhand)
            {
            alert(" Qty ordered is missing or greater than Qty on hand. ");
            document.forms["form1"].elements["orderqty"].focus();
            }
            }
            </SCRIPT>



            *** Sent via Developersdex http://www.developersdex.com ***
            Don't just participate in USENET...get rewarded for it!

            Comment

            • kaeli

              #7
              Re: Form validation - undefined field

              In article <415d7343$0$261 33$c397aba@news .newsgroups.ws> , guddemi@hotmail .com
              enlightened us with...[color=blue]
              > Thanks for cleaning up the code.
              > The javascript does indicate that the qtyonhand field is missing. I know
              > i am missing something here.[/color]

              Yeah, a form field with it in there. ;)
              [color=blue]
              > Got to go thru the learning curve. Thanks for your help.
              > view source posted below.[/color]

              And from looking at it, it should be obvious that the field is indeed
              missing. *grins*

              So, the error has nothing to do with your javascript.
              It's the ASP that's supposed to be generating the field.

              Your ASP is generating invalid html. You've got a missing end table cell tag
              (very important) and no end form tag (pretty important). I cleaned up the
              code, removing style and other stuff I didn't need, to see it properly. What
              I saw was an absolute mess.

              You've also got some odd spans with nothing in them and stuff (just odd).
              You've got style attributes in a font tag (this might be bad).
              You need to fix your ASP to make valid html.
              Then you need to fix it so it puts the form field where it belongs. It put
              the number 3 there instead. ;)

              <input name="orderqty" id="orderqty" size="13" maxlength="7">
              <TD BGCOLOR="#FFFFC C" ALIGN=middle><d iv align="right">< FONT SIZE=2[color=blue]
              >[/color]
              3
              <STRONG><FONT face="Trebuchet MS"><FONT
              style="BACKGROU ND-COLOR:
              #ffffff"></FONT></STRONG></FONT></div></TD>

              Put the end table cell (</td>) tag after the orderqty input box.
              Whatever made this put a 3 in that table cell when I suspect you wanted a
              form field, not the value.
              If you wanted the value as it is, it still has to be in a form field the way
              your script is written. Put it in a hidden form field if you want it not to
              display as such.

              Looking at your other post, I see this:
              <input name="orderqty" id="orderqty" size="13" maxlength="7">
              <TD BGCOLOR="#FFFFC C" ALIGN=middle><d iv align="right">< FONT SIZE=2[color=blue]
              >[/color]
              <%
              Response.Write FormatNumber(rs tINMST("qtyonha nd"),0)
              qtyoh = rstINMST("qtyon hand")
              %>
              <STRONG><FONT face="Trebuchet MS"><FONT
              style="BACKGROU ND-COLOR:
              #ffffff"></FONT></STRONG></FONT></div></TD>

              Change that to (no line breaks intended watch for word-wrap):
              <input name="orderqty" id="orderqty" size="13" maxlength="7">
              </td>
              <TD BGCOLOR="#FFFFC C" ALIGN=middle><d iv align="right">< FONT SIZE=2>
              <%
              v_qtyonhand = FormatNumber(rs tINMST("qtyonha nd"),0)
              Response.Write v_qtyonhand
              qtyoh = rstINMST("qtyon hand")
              %>
              <input type="hidden" name="qtyonhand " id="qtyonhand" value="<%
              =v_qtyonhand%>" >
              <STRONG><FONT face="Trebuchet MS"><FONT style="BACKGROU ND-COLOR:
              #ffffff"></FONT></STRONG></FONT></div></TD>

              Oh, but ditch the weird font thing while you're at it. Use span for the
              background color. This is just too odd looking, even if it does work in IE.
              ;)

              HTH

              --
              --
              ~kaeli~
              With her marriage, she got a new name and a dress.



              Comment

              Working...