aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes Javascript and HTML issue Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Javascript and HTML issue" Watch "Javascript and HTML issue" New topic
Author

Javascript and HTML issue

Sharadha Sankar
Greenhorn

Joined: Feb 15, 2006
Posts: 20
Hello,

I have two questions

1. I have a form which I have to validate. I have written the validations for all the fields as separate functions in Validation.js file. Now, when I hit submit how do I ensure all the functions are invoked. and if it passes validation, to enter values into the database?

2. Is it possible to call the corresponding validation function(Which are all in the same file)for each input field from the html form .

Please help...I am desperate.

Thanks
sharadha
[ April 11, 2006: Message edited by: Bear Bibeault ]

Thanks<br />Sharadha
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15357
    
    6
1. Use the onsubmit handler that calls a function that does the validation

2. You looking at onchange?

Eric
Sharadha Sankar
Greenhorn

Joined: Feb 15, 2006
Posts: 20
But my javascript file has like 15 functions, how can run all the 15 function using onsubmit handler?

Thanks in advance
Sharadha
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15357
    
    6
Have one function that calls all 15 function

function Validate(){

var isValid = true;
if(!function1())isValid = false;
if(!function2())isValid = false;
if(!function3())isValid = false;
if(!function4())isValid = false;
return isValid
}

you could also do it

if(!function1()||!function2()||!function3())isValid = false;

Someway you need to call every function

Eric
Linda Walters
Ranch Hand

Joined: Apr 30, 2005
Posts: 100
Another possible solution is to validate the entry for each widget when the user tabs off of it and it loses focus and fires the onBlur event. This is possible if the various widgets can be validated in isolation. This is good for checking for numbers and not letters in a phone number field or letters and not number in a name field, etc.

If each field (or at least most of them) can be validated individually, then any combination validation can be done by the onSubmit event handler.

It is also a better user experience if you tell the user that their phone number, for example, is invalid because it has a letter as soon as they enter the phone number, not at the bottom of the form after they have filled in 20 more fields.


<a href="http://labryssystems.net/pblog/index.php" target="_blank" rel="nofollow">Javaville Gazette</a><br />Non-cooperation with evil is a duty. -- Mahatma Gandhi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javascript and HTML issue
 
Similar Threads
Core JSF, Chapter 12: Client-side validation
Validation in Struts
Validation of Long Forms
Strange - Page Submits!!!
difference between struts and jsp