473,386 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Form validation - undefined field

tm
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="JavaScript" TYPE="text/javascript">
function btnValidate_onclick()
{
var myform = document.form1;
var qtyonhand = myform.qtyonhand.value;
alert( myform.orderqty.value + " ");
if(myform.orderqty.value=='' || myform.orderqty.value > qtyonhand)

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


Jul 23 '05 #1
6 4999
Lee
tm said:

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="JavaScript" TYPE="text/javascript">
function btnValidate_onclick()
{
var myform = document.form1;
var qtyonhand = myform.qtyonhand.value;


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.

Jul 23 '05 #2
tm
The field qtyonhand is a form field displayed within the table, sorry
for the confusion.

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

<table width="600" border="0" align="center">
<tr>
<td width="640"><div align="center" class="ms-separator"><font
face=Arial size=4>Storage and Moving Company </font></div></td>
</tr>
<tr>
<td><div align="center" class="style5"><FONT face="Arial"
size="3">Customer Order Entry Page</FONT></div></td>
</tr>
<tr>
<td><div align="center" class="style5"><FONT face=Arial><span
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><STRONG><FONT size="2" face=Tahoma> Item Number
</FONT></STRONG></P></TH>
<TH ALIGN=middle WIDTH="250"> <P align=left><STRONG><FONT size="2"
face=Tahoma> Description</FONT></STRONG></P></TH>
<TH ALIGN=middle WIDTH="100"> <P><STRONG><FONT size="2"
face=Tahoma>Enter Order Amount </FONT></STRONG></P></TH>
<TH ALIGN=middle WIDTH="100"> <div align="center"><font size="2"
face="Tahoma">Qty Available </font></div></TH>
</TR>
<%
Do While Not rstINMST.EOF
%>
<TR>
<TD BGCOLOR="#FFFFFF" ALIGN=middle><P align=left>
<FONT SIZE=2
<div align="left">
<% =rstINMST("ITMNUM") %>
</A> </div></TD>
<TD BGCOLOR="#FFFFFF" align=middle><div align="left"><FONT SIZE=2 <%
Response.Write rstINMST("ITMDESC")
%>
</FONT> </div></TD>
<TD BGCOLOR="#FFFFFF" ALIGN=right>
<FONT SIZE=2 <input name="orderqty" id="orderqty" size="13" maxlength="7">
<TD BGCOLOR="#FFFFCC" ALIGN=middle><div align="right"><FONT SIZE=2

<%
Response.Write FormatNumber(rstINMST("qtyonhand"),0)
qtyoh = rstINMST("qtyonhand")
%>
<STRONG><FONT face="Trebuchet MS"><FONT
style="BACKGROUND-COLOR:
#ffffff"></FONT></STRONG></FONT></div></TD>
</TR>
<%
rstINMST.movenext
loop
%>
</TABLE>

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

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


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3
Lee
tm said:

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

Relevant HTML.


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(rstINMST("qtyonhand"),0)
qtyoh = rstINMST("qtyonhand")
%>

Jul 23 '05 #4
In article <41********@news.lh.net>, to******@hotmail.com enlightened us
with...
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...


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="JavaScript" TYPE="text/javascript">
function btnValidate_onclick()
{
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(document.forms["form1"].elements
["qtyonhand"].value,10);
var v_orderqty = parseInt(document.forms["form1"].elements
["orderqty"].value,10);

if (isNaN(v_qtyonhand) || isNaN(v_orderqty))
{
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.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #5
tm
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>Customer 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="CustOrder06.asp" name=form1>

<table width="600" border="0" align="center">
<tr>
<td width="640"><div align="center" class="ms-separator"><font
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">Customer Order Entry Page</FONT></div></td>
</tr>
<tr>
<td><div align="center" class="style5"><FONT face=Arial><span
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><STRONG><FONT size="2" face=Tahoma> Item Number
</FONT></STRONG></P></TH>
<TH ALIGN=middle WIDTH="250"> <P align=left><STRONG><FONT size="2"
face=Tahoma> Description</FONT></STRONG></P></TH>
<TH ALIGN=middle WIDTH="100"> <P><STRONG><FONT size="2"
face=Tahoma>Enter Order Amount </FONT></STRONG></P></TH>
<TH ALIGN=middle WIDTH="100"> <div align="center"><font size="2"
face="Tahoma">Qty Available </font></div></TH>
</TR>

<TR>
<TD BGCOLOR="#FFFFFF" ALIGN=middle><P align=left>
<FONT SIZE=2
<div align="left">
EGIJB24-4
</A> </div></TD>
<TD BGCOLOR="#FFFFFF" align=middle><div align="left"><FONT SIZE=2 24 X INK JET ROLL
</FONT> </div></TD>
<TD BGCOLOR="#FFFFFF" ALIGN=right>
<FONT SIZE=2 <input name="orderqty" id="orderqty" size="13" maxlength="7">
<TD BGCOLOR="#FFFFCC" ALIGN=middle><div align="right"><FONT SIZE=2

3
<STRONG><FONT face="Trebuchet MS"><FONT
style="BACKGROUND-COLOR:
#ffffff"></FONT></STRONG></FONT></div></TD>
</TR>

</TABLE>

</div>
<p align="center"><span class="style10"><span class="style2">
<input type="button" name="btnValidate" value="Validate"
onclick="btnValidate_onclick()">
<input name="Submit" type="submit" value="Continue">
</span></span></p>
<p><strong>
</strong></P>
<table width="364" border="0">
<tr>
<td width="172"><span class="style3">For technical questions email
</span></td>
<td width="176"><a href="mailto:we*******@fordstorage.com"
class="style4">Web Development </a></td>
</tr>
<tr>
<td><span class="style3">For questions concerning
balances</span></td>
<td><a href="mailto:bs******@fordstorage.com" class="style4">Becky
Schramm</a></td>
</tr>
</table>
</body>
</html>

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
function btnValidate_onclick()
{
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(document.forms["form1"].elements
["qtyonhand"].value,10);
var v_orderqty = parseInt(document.forms["form1"].elements
["orderqty"].value,10);

if (isNaN(v_qtyonhand) || isNaN(v_orderqty))
{
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!
Jul 23 '05 #6
In article <41**********************@news.newsgroups.ws>, gu*****@hotmail.com
enlightened us with...
Thanks for cleaning up the code.
The javascript does indicate that the qtyonhand field is missing. I know
i am missing something here.
Yeah, a form field with it in there. ;)
Got to go thru the learning curve. Thanks for your help.
view source posted below.
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="#FFFFCC" ALIGN=middle><div align="right"><FONT SIZE=2 3
<STRONG><FONT face="Trebuchet MS"><FONT
style="BACKGROUND-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="#FFFFCC" ALIGN=middle><div align="right"><FONT SIZE=2

<%
Response.Write FormatNumber(rstINMST("qtyonhand"),0)
qtyoh = rstINMST("qtyonhand")
%>
<STRONG><FONT face="Trebuchet MS"><FONT
style="BACKGROUND-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="#FFFFCC" ALIGN=middle><div align="right"><FONT SIZE=2>
<%
v_qtyonhand = FormatNumber(rstINMST("qtyonhand"),0)
Response.Write v_qtyonhand
qtyoh = rstINMST("qtyonhand")
%>
<input type="hidden" name="qtyonhand " id="qtyonhand" value="<%
=v_qtyonhand%>">
<STRONG><FONT face="Trebuchet MS"><FONT style="BACKGROUND-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.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Eddie | last post by:
I have a form that's used to sort a series of items. The form has a number of text fields. Each text field should contain a number. When the form is submitted I would like to do two things: ...
72
by: Stephen Poley | last post by:
I have quite often (as have probably many of you) come across HTML forms with irritating bits of Javascript attached. The last straw on this particular camel's back was a large form I was asked to...
2
by: dustbort | last post by:
I recently had a problem where my required field validator stopped working. But, the page still posted back and tried to insert a record into the database without performing server-side validation....
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
1
by: Nigel | last post by:
Hello, I am creating a Perl CGI page with Javascript which I believe has a problem with the javascript. Below is my form which has two submit buttons with two different actions. I am having...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
18
by: Axel Dahmen | last post by:
Hi, trying to submit an ASPX form using the key (using IE6) the page is not submitted in my web project. Trying to debug the pages' JavaScript code I noticed that there's some ASP.NET client...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
2
by: plumba | last post by:
Ok, another problem... A bit querky this one.. My form calls an onsubmit function to check fields for completion (validation check). Here is a breakdown version of the form: <html>...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.