473,773 Members | 2,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

submiting after for loop in page validations

I have a for statement in my validation process
I do a for loop becasue I don't know how many rows of items there are...I
need to validate each item in each row.
If I remove the "document.f orms[0].submit(); it works perfectly...the code
stops at each field that is not formated properly...but never submits.
However if I leave the submit() in there, the page submits before they have a
chance to fix problems.

How can I get both to work properly?
function validate(){
for(i=1;i<=rows ;i++){
if(column 1 is formated right){
alert("message" );
here.focus();
}
if (column 2 is formated right){
alert("message" );
here.focus();
}

document.forms[0].submit();
}
Jul 23 '05 #1
6 1434
Abby Lee wrote:
I have a for statement in my validation process
I do a for loop becasue I don't know how many rows of items there are...I
need to validate each item in each row.
If I remove the "document.f orms[0].submit(); it works perfectly...the code
stops at each field that is not formated properly...but never submits.
However if I leave the submit() in there, the page submits before they have a
chance to fix problems.

How can I get both to work properly?
function validate(){
for(i=1;i<=rows ;i++){
if(column 1 is formated right){
alert("message" );
here.focus();
}
if (column 2 is formated right){
alert("message" );
here.focus();
}

document.forms[0].submit();
}

This will always submit the form, include a "return false" after an
error, or better yet rewrite the function so that it returns a boolean
value.

<form onsubmit="retur n validate()">
Mick
Jul 23 '05 #2
Abby Lee wrote:
I have a for statement in my validation process
I do a for loop becasue I don't know how many rows of items there
are...I need to validate each item in each row.
If I remove the "document.f orms[0].submit(); it works perfectly...the
code stops at each field that is not formated properly...but never
submits. However if I leave the submit() in there, the page submits
before they have a chance to fix problems.

How can I get both to work properly?
function validate(){
for(i=1;i<=rows ;i++){
if(column 1 is formated right){
alert("message" );
here.focus();
}
if (column 2 is formated right){
alert("message" );
here.focus();
}

document.forms[0].submit();
}


This idea you have that javascript that is supposed to interact with
HTML can be considered in isolation form the HTML it is interacting with
is misguided.

Normal form validation is done by putting an - onsubmit - attribute in
the opening form tag that calls the validation function and returns
whatever value that function returns:-

<form name="x" action="http://example.com/exPage.jsp"
onsubmit="retur n validateThisFor m(this);">

- The example - validateThisFor m - function would then return - false -
if the form did not validate (cancelling the submission of the form and
giving the user a chance to correct it), or it would return - true - and
allow the form to be submitted.

Your function returns neither true or false, and you have not provided
any information on the context in which it is used. But, generally,
directly calling the - submit - method of a form is a bad idea that
results in a client-side scripting dependency that is avoidable with the
normal use of HTML forms and offers no benefits in return for that
needless dependency.

Richard.
Jul 23 '05 #3
Mick White <mw******@BOGUS rochester.rr.co m> writes:
Abby Lee wrote:
I have a for statement in my validation process
I do a for loop becasue I don't know how many rows of items there are...I

need to validate each item in each row.
If I remove the "document.f orms[0].submit(); it works perfectly...the
code
stops at each field that is not formated properly...but never submits.
However if I leave the submit() in there, the page submits before they
have a
chance to fix problems.

How can I get both to work properly?
function validate(){
for(i=1;i<=rows ;i++){
if(column 1 is formated right){
alert("message" );
here.focus();
}
if (column 2 is formated right){
alert("message" );
here.focus();
}

document.forms[0].submit();
}

This will always submit the form, include a "return false" after an
error, or better yet rewrite the function so that it returns a boolean
value.

<form onsubmit="retur n validate()">
Mick

My code just submits without doing any validation. Understand I'm new to
this..can you be of more help?

function validate(){
for(i=1;i<=rows ;i++){
if(column 1 is formated right){
alert("message" );
here.focus();
return false;
}
if (column 2 is formated right){
alert("message" );
here.focus();
return false;
}
}

--------<sbip>---------
<input type="submit" name="Submit" value="Submit Changes" onSubmit="retur n
validate()">
Jul 23 '05 #4
Abby Lee wrote:
My code just submits without doing any validation. Understand I'm new to
this..can you be of more help?

function validate(){
for(i=1;i<=rows ;i++){
if(column 1 is formated right){
alert("message" );
here.focus();
return false;
}
if (column 2 is formated right){
alert("message" );
here.focus();
return false;
}
}


I am not sure if you're trying to validate form elements, it seems not.
First, I would name the function something meaningful.
function validateColumnF ormat(){
for(i=1;i<=rows ;i++){
if(column 1 is formatted wrong){
alert("message" );
here.focus();
return false;
}
if (column 2 is formatted wrong){
alert("message" );
here.focus();
return false;
}
}
return true;
}

Then you may test the condition:

if(validateColu mnFormat()){ //do stuff }

Or set a boolean , dependant on the condition:
var ready=validateC olumnFormat();
Or a variable
var foobar=validate ColumnFormat()? "white":"gr ey";

Mick

Jul 23 '05 #5
Abby Lee wrote:
I have a for statement in my validation process
I do a for loop becasue I don't know how many rows of items there are...I
need to validate each item in each row.
[...]
function validate(){
for(i=1;i<=rows ;i++){


Non sequitur. A "for" loop is determined and as such the exact opposite
of what you want to do if you do not know the number of rows, unless your
evil[tm] global "rows" determines the number of rows previously (if so,
then why don't you determine it within the method?).
PointedEars
Jul 23 '05 #6
You can just use an ordinary submit button -- take that
submit() line out of the code. Then, add the following
to the <form> declaration:

onsubmit="retur n validateForm(); "

Then, have your function keep a boolean (true/false),
declared true at the top, and make it false if the
validation fails at any point. Return that value
at the end of the function.

Example:

function validateAddPage (){

var allOkay = true;
var errMsg = '';

if (document.forms['frmAdd'].txtTitle.value == ''){
errMsg = errMsg + 'A project title must be entered.\n';
var allOkay = false;
}

if (document.forms['frmAdd'].drpRelevance.s electedIndex == 0){
errMsg = errMsg + 'A strategic relevance must be entered.\n';
var allOkay = false;
}

if (document.forms['frmAdd'].drpCompany.sel ectedIndex == 0){
errMsg = errMsg + 'A company must be entered.\n';
var allOkay = false;
}

if (document.forms['frmAdd'].txtCompletion. value == ''){
errMsg = errMsg + 'A requested completion date must be entered.\n';
var allOkay = false;
}

if (!allOkay){aler t(errMsg);}

return allOkay;

}
Jul 23 '05 #7

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

Similar topics

2
13072
by: Bartosz Wegrzyn | last post by:
I use onblue event to validate fields in my form. I do this onblur="return isname()" and so so ... I have one form with 20 fields. My problem is that when the focus is for example on the first field of my form the "name" field and I click somewher or press tab than I loose focus and my isname() function is executed. Everything is fine but the focus was change for next field
0
1557
by: Niks | last post by:
Hi, I am creating a simple .aspx page to add some fields with validation. I have used different .NET validations like REquiredFieldValidator, RegularExpressionValidator and showed the summary in the bulleted list on top. I have 3 text boxes, and two RadioButtonList. and 3 buttons. One for Submit, Reset and Exit. If submit is pressed page should be validated and submit (insert into
3
2604
by: Arun K | last post by:
Hi, I am creating a simple .aspx page to add some fields with validation. I have used different .NET validations like REquiredFieldValidator, RegularExpressionValidator and showed the summary in the bulleted list on top. I have 3 text boxes, and two RadioButtonList. and 3 buttons. One for Submit, Reset and Exit. If submit is pressed page should be validated and submit (insert into
5
1889
by: rodrigo21 | last post by:
I have a form that submits the form values to the same page (of the form). The database is feed from the same page that have the form in it. So the action attribute would look like this <form action="samepage.php" Right now, after submiting, the same form opens, so the user dont know if his record was submited. Saying this. How can I do to: after sumniting the form, go to another page that tells "your record is submited"
0
9621
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
9454
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
10106
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
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
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...
1
4012
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
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.