473,657 Members | 2,604 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="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>


Jul 23 '05 #1
6 5021
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="JavaS cript" TYPE="text/javascript">
function btnValidate_onc lick()
{
var myform = document.form1;
var qtyonhand = myform.qtyonhan d.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="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
<div align="left">
<% =rstINMST("ITMN UM") %>
</A> </div></TD>
<TD BGCOLOR="#FFFFF F" align=middle><d iv align="left"><F ONT SIZE=2 <%
Response.Write rstINMST("ITMDE SC")
%>
</FONT> </div></TD>
<TD BGCOLOR="#FFFFF F" ALIGN=right>
<FONT SIZE=2 <input name="orderqty" id="orderqty" size="13" maxlength="7">
<TD BGCOLOR="#FFFFC C" ALIGN=middle><d iv align="right">< FONT SIZE=2

<%
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!
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(rs tINMST("qtyonha nd"),0)
qtyoh = rstINMST("qtyon hand")
%>

Jul 23 '05 #4
In article <41********@new s.lh.net>, to******@hotmai l.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="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.
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>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
<div align="left">
EGIJB24-4
</A> </div></TD>
<TD BGCOLOR="#FFFFF F" align=middle><d iv align="left"><F ONT SIZE=2 24 X INK JET ROLL
</FONT> </div></TD>
<TD BGCOLOR="#FFFFF F" ALIGN=right>
<FONT SIZE=2 <input name="orderqty" id="orderqty" size="13" maxlength="7">
<TD BGCOLOR="#FFFFC C" ALIGN=middle><d iv align="right">< FONT SIZE=2

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 *******@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 ******@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!
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="#FFFFC C" ALIGN=middle><d iv align="right">< FONT SIZE=2 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

<%
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.
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
4582
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: 1. Verify that only numbers are entered in each text field. 2. Verify that there are no duplicate entries in any text field. So each field should be a unique number. Another thing complicating this is that I do not know how many fields I will...
72
5188
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 complete in connection with attendance at a seminar. After spending more than 15 minutes on it, I clicked on the submit button - and nothing happened. Looking round the pages on Javascript form validation that Google produced for me (well,...
2
4508
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. I discovered that there was no aspnet_client folder in the root of my IIS Web site, and when I ran "aspnet_regiis -c", client-side validation was working again. However, what I don't understand is why the required field validator did not...
9
4167
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 honest I usually hire someone to do it for me, grab predone scripts and kind of hack out the parts that I need, or just do very minimal validation (e.g. this is numeric, this is alpha-numeric, etc.)
1
1417
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 an issue with my "Submit FAQ" button. The "Submit FAQ" button calls the javascript function validate(). This function is supposed to check to make sure the 'content' field is populated. If
11
2986
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 certain fields match certain criteria, and inform the user in different ways when the data is wrong (offcourse, this will be checked on posting the data again, but that's something I've got a lot of experience with). Now, offcourse it's...
18
5791
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 script code being executed having a flaw: function anonymous() { if (!ValidatedTextBoxOnKeyPress(event)) { event.cancelBubble = true; if (event.stopPropagation) event.stopPropagation(); return false; } }
7
3601
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
1732
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> <script> function toggle_display() { var form = document.getElementById('hidesubmit');
0
8385
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8303
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8821
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8723
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.