473,320 Members | 1,955 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,320 software developers and data experts.

Validation Problem

I'm tring to use a validation function example from WROX that looks at
form fields on a submit. I can't seem to launch it. I have 2 other
functions up in the header that work fine. Any help appreciated. Here is
the code and form:
<script type='text/javascript'>
function form1_onsubmit()
{
var form = document.MyInput
var controlCounter;
var returnValue = true;
var formControl;

for controlCounter = 0; controlCounter < form.length; controlCounter++)
{
formControl = form.elements[controlCounter];
if (formControl.type == "text" && formControl.value =="")
{
alert("Please complete all fields");
formControl.focus();
returnValue = false;
break;
}
}
return returnValue;
}

</script>
</head>

<Table border="1" Width=100%>

<form action="MyInsert.asp" method="Post" name="MyInput"
LANGUAGE=JavaScript onsubmit="return form1_onsubmit()">
<TR>
<td width=20%><input type="TEXT" name="ExDate2" onkeypress="if
(event.keyCode == 13)
{document.getElementById('next').focus();return
false;}">&nbsp;</td>
<td width=20%><SELECT name="Expense2" id="next" onkeypress="if
(event.keyCode == 13)
{document.getElementById('next2').focus();return
false;}"onchange='javascript:Titleonchange();'><Op tion value="Select"
Selected>
<Option Value="Car">Car
<Option Value="Meals">Meals
<Option Value="Air">Air
<Option Value="Phone">Phone</select>&nbsp;</td>

<td width=20%><input type="INPUT" READONLY=TRUE
name="ExCode2">&nbsp;</td>
<td width=20%><input type="TEXT" id="next2" name="Amount2">&nbsp;</td>
<td width=20%><input type="SUBMIT" value="Submit"></td>
</tr>
</table>
thanks,
Frank

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
2 3324
DU
Frank Py wrote:
I'm tring to use a validation function example from WROX that looks at
form fields on a submit. I can't seem to launch it. I have 2 other
functions up in the header that work fine. Any help appreciated. Here is
the code and form:
<script type='text/javascript'>
function form1_onsubmit()
{
var form = document.MyInput
var controlCounter;
var returnValue = true;
var formControl;

for controlCounter = 0; controlCounter < form.length; controlCounter++)
I did not check the whole code - missing an ( - but this line should
have brought up the javascript debugger or your javascript console:

for (controlCounter = 0; controlCounter < form.length; controlCounter++)
{
formControl = form.elements[controlCounter];
if (formControl.type == "text" && formControl.value =="")
{
alert("Please complete all fields");
formControl.focus();
returnValue = false;
break;
}
}
return returnValue;
}

Your form1_onsubmit() function could be optimize to be more efficient.
</script>
</head>

<Table border="1" Width=100%>

Form should not be inside table. Table should be inside form. This is a
classic validation error (improper nesting). Also, there is no point to
setting the width of a table to 100% since the default value of width is
100% of its parent node.
<form action="MyInsert.asp" method="Post" name="MyInput"
LANGUAGE=JavaScript onsubmit="return form1_onsubmit()">
LANGUAGE=JavaScript should not be in there.
<TR>
<td width=20%><input type="TEXT" name="ExDate2" onkeypress="if
(event.keyCode == 13)
{document.getElementById('next').focus();return
false;}">&nbsp;</td>
event.keyCode == 13 means that only MSIE can support and will support
this page. If you want a tab behavior on an <enter> keypress, then there
is a cross-browser way to do this.
<td width=20%><SELECT name="Expense2" id="next" onkeypress="if
(event.keyCode == 13)
{document.getElementById('next2').focus();return
false;}"onchange='javascript:Titleonchange();'><Op tion value="Select"
Selected>
You can safely remove "javascript:" in the onchange attribute value:
this achieves nothing.

<Option Value="Car">Car
<Option Value="Meals">Meals
<Option Value="Air">Air
<Option Value="Phone">Phone</select>&nbsp;</td>

<td width=20%><input type="INPUT" READONLY=TRUE
name="ExCode2">&nbsp;</td>
It's readonly. Not READONLY=TRUE. Note that no browser now seems to
support correctly the readonly attribute.

http://www.w3.org/TR/html4/interact/...#adef-readonly
<td width=20%><input type="TEXT" id="next2" name="Amount2">&nbsp;</td>
<td width=20%><input type="SUBMIT" value="Submit"></td>
Usually forms have a reset button too and an onreset form event handler.

width=20% will be interpreted as 20px while
width="20%" will be interpreted as 20% of its parentNode given width.

Just by giving wrapping all your attribute values in double quotes, you
make your page get parsed and rendered faster and you avoid this kind of
error.

3.4. Should I put quotes around attribute values?
http://www.htmlhelp.com/faq/html/basics.html#quotes

"By default, SGML requires that all attribute values be delimited using
either double quotation marks(...)"
http://www.w3.org/TR/html4/intro/sgm...tml#attributes
</tr>
</table>
Your form end tag is not found: so, improper nesting here also.
thanks,
Frank

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

You really should validate your whole document, use a doctype
declaration, etc..

http://validator.w3.org/

Activating the Right Layout Mode Using the Doctype Declaration
http://www.hut.fi/u/hsivonen/doctype.html

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/

Jul 20 '05 #2
Thanks for your analytical pointers. I was able to get it going with
your help.

Sincerely,
Frank

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

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

Similar topics

2
by: diong | last post by:
please help! i have a form validation problem. here is the code if ((form1.Decline.value=='') && (form1.OfficeStatus == "YES") & (form1.FloorBldgDiscStat.value=='')) { alert('Enter value on...
0
by: Brian | last post by:
I am having alot of trouble getting a XML document validated with a schema. I got a sample document and schema off of w3schools.com, which passed an online xml validator:...
4
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a...
3
by: Michael Skulsky | last post by:
Hi all, I've got the following validation problem. There are 2 schemas and a document: ----------------------------------------------------------------- bar.xsd ====== <?xml version="1.0"...
2
by: Shahar | last post by:
hi I have the following problem: I have two button, tow textboxes and two RequiredFieldValidator controls, like that: <form id="Form1" method="post" runat="server"> <asp:TextBox id="TextBox1"...
2
by: TIBM | last post by:
Hi. I've posted this question on another newsgroup, but I haven't received any answers.. I have a login page where users input userID and password and click a Login button. Before calling the ...
0
by: koen | last post by:
Hi! In asp.net (version 1.1) I run into a problem when trying to perform client validation. The error I get on the client-side is : "Error: expected ';'". This problem occurs when I place a...
5
by: Tina | last post by:
the Edit, Update, Cancel, and Delete buttons in my datagrid are causing validation elsewhere on the page. I want to specify that these buttons should not cause validation but they have no design...
6
by: tshad | last post by:
I have been having some issues trying to get validation to work. On most of my pages, I have no problem. But I have a page that has 4 validation objects and none are displaying an error...
5
by: Kuldeep | last post by:
Framework: Visual Studio 2005 Technology: ASP.NET 2.0 Language: C#.NET 2.0 Hi All, We have developed a Web Application on Visual Studio 2005 (ASP.NET 2.0) and deployed it on the Client's...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.