473,569 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.MyInpu t
var controlCounter;
var returnValue = true;
var formControl;

for controlCounter = 0; controlCounter < form.length; controlCounter+ +)
{
formControl = form.elements[controlCounter];
if (formControl.ty pe == "text" && formControl.val ue =="")
{
alert("Please complete all fields");
formControl.foc us();
returnValue = false;
break;
}
}
return returnValue;
}

</script>
</head>

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

<form action="MyInser t.asp" method="Post" name="MyInput"
LANGUAGE=JavaSc ript onsubmit="retur n form1_onsubmit( )">
<TR>
<td width=20%><inpu t type="TEXT" name="ExDate2" onkeypress="if
(event.keyCode == 13)
{document.getEl ementById('next ').focus();retu rn
false;}">&nbsp; </td>
<td width=20%><SELE CT name="Expense2" id="next" onkeypress="if
(event.keyCode == 13)
{document.getEl ementById('next 2').focus();ret urn
false;}"onchang e='javascript:T itleonchange(); '><Option value="Select"
Selected>
<Option Value="Car">Car
<Option Value="Meals">M eals
<Option Value="Air">Air
<Option Value="Phone">P hone</select>&nbsp;</td>

<td width=20%><inpu t type="INPUT" READONLY=TRUE
name="ExCode2"> &nbsp;</td>
<td width=20%><inpu t type="TEXT" id="next2" name="Amount2"> &nbsp;</td>
<td width=20%><inpu t 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 3336
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.MyInpu t
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.ty pe == "text" && formControl.val ue =="")
{
alert("Please complete all fields");
formControl.foc us();
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="MyInser t.asp" method="Post" name="MyInput"
LANGUAGE=JavaSc ript onsubmit="retur n form1_onsubmit( )">
LANGUAGE=JavaSc ript should not be in there.
<TR>
<td width=20%><inpu t type="TEXT" name="ExDate2" onkeypress="if
(event.keyCode == 13)
{document.getEl ementById('next ').focus();retu rn
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%><SELE CT name="Expense2" id="next" onkeypress="if
(event.keyCode == 13)
{document.getEl ementById('next 2').focus();ret urn
false;}"onchang e='javascript:T itleonchange(); '><Option value="Select"
Selected>
You can safely remove "javascript :" in the onchange attribute value:
this achieves nothing.

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

<td width=20%><inpu t 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%><inpu t type="TEXT" id="next2" name="Amount2"> &nbsp;</td>
<td width=20%><inpu t 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
1484
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 floorbldgstat') return (false); }
0
4100
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: http://tools.decisionsoft.com/schemaValidate.html. I cannot, however, get them validated programmatically. The documents are:
4
2621
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 script that validates the form fields. the validation procedure is called ONCLICK event of the submit button. Follwowing is the structure of the...
3
1766
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" encoding="UTF-8"?> <schema xmlns:bar="urn:bar" targetNamespace="urn:bar"
2
3390
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" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ControlToValidate="TextBox1" id="RequiredFieldValidator1" runat="server"...
2
1365
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 login functions, I have to check the user ID and the password for invalid data. It works well in IExplorer, but it doesn't show the validation summary...
0
1141
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 specific UserControl (that doesn't have validation) on a wepage together with other UserControls that do have validation.
5
2037
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 time property of causevalidation. How can I keep them from causing validation? Thanks, T
6
1253
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 message, but I have this code: trace.warn("Before Test on Page.IsValid") if not Page.IsValid then Exit Sub trace.warn("After Test on Page.IsValid")
5
5797
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 Server. Apparently, we have used a lot of ASP Validation Controls in our pages all
0
7695
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...
0
7612
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...
0
7922
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. ...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
3653
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...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
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
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
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...

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.