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

return true / return false validation

15
Hi

Basically, this is the last function called and checks if there were any errors, if so it returns all the errors in one alert message, if not form should proceed on submit.

So if there is an alert(msg) returned, I don't want the form to submit.

Any suggestions on how to add this would be appreciated.

Expand|Select|Wrap|Line Numbers
  1.  
  2. function addMsg(){
  3.     alert(msg)
  4.     msg = ""
  5. }
  6.  
  7.  
  8.  
Aug 21 '07 #1
3 2030
pbmods
5,821 Expert 4TB
Heya, MKO.

The basics behind form validation, of course, is that your validation function will return false if the data doesn't validate, which will prevent the form from submitting.

With that in mind, your best bet would be to either use an inner function, or to scrap the function idea altogether. For example:

Expand|Select|Wrap|Line Numbers
  1. function validateForm(thePfhorm)
  2. {
  3.     var errors = [];
  4.  
  5.     if( ! thePfhorm.firstname.value )
  6.     {
  7.         errors.push("You didn't enter your first name, dummy!");
  8.     }
  9.  
  10.     if( ! thePfhorm.lastname.value )
  11.     {
  12.         errors.push("How about a last name, too?");
  13.     }
  14.  
  15.     .
  16.     .
  17.     .
  18.  
  19.     if( errors.length > 0 )
  20.     {
  21.         alert(errors.join('\n'));
  22.         return false;
  23.     }
  24.  
  25.     return true;
  26. }
  27.  
P.S., I believe you're looking for [code=javascript] ~_^
Aug 21 '07 #2
MKO
15
Thanks, that is exactly what I think I am looking for, will check it out tomorrow.

Cheers

M
Aug 21 '07 #3
pbmods
5,821 Expert 4TB
Heya, M.

Good luck with your project, and if you ever need anything, post back anytime :)
Aug 22 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Mark Jerde | last post by:
I'm trying to learn the very basics of using an unmanaged C++ DLL from C#. This morning I thought I was getting somewhere, successfully getting back the correct answers to a C++ " int SumArray(int...
5
by: siaj | last post by:
Hello, I have a javascript function for a validation in the HTML page of the asp.Net page.. I call this function in a Savebutton click When the validation fails No postback should happen ( ie...
8
by: bdobby | last post by:
Hi. I am relatively new to js, but I did think I was starting to get the hang of it. Then this happened... I have a form with an onsubmit event handler: <form id="uploadForm" method="post"...
14
by: dcassar | last post by:
I have had a lively discussion with some coworkers and decided to get some general feedback on an issue that I could find very little guidance on. Why is it considered bad practice to define a...
13
by: kurtj | last post by:
Hello Gurus: I have a validation script (below) that is somehow messed up. If the Name field is blank, I get the alert message, then the browser window goes to a blank document with the word...
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....
1
by: mailpitches | last post by:
X-No-Archive: yes a function, the return value of the function is a boolean. What does this boolean value mean? Example: <body onload="document.getElementById('field').onkeydown=function(x) {...
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...
8
by: Peter Afonin | last post by:
Hello, I'm using Javascript in ASP.NET application to check whether at least one checkbox in datagrid has been checked. If validation fails, the user gets a warning. If he clicks OK, the form is...
1
by: Sudarhan | last post by:
Hello frnds I have created a webbased form using asp and javascript .. while submitting the form i am validating the fields in the form .it validates the field and returns alert message. but when...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.