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

Ajax Server Validation Question

Hi,

Im doing a maintenance application in ajax and coldfusion at work on IE6
exclusively. I have a save button on each form and i have to do various
validations server side and on client side when the user clicks save i.e
check that user exists in table, check users password is the same as
password in table, check password is valid, check that logged in user is a
super user etc etc to get the correct error message. Different forms may or
may not use all of these validations and not always in the same order. At
the moment for each form, im calling the first validation when user hits
save, then in that callback function im checking to see if its been
validated, if it has then run the next validation function and so on, so its
like a cascading effect. Is there a better way of doing this? so i can reuse
code on different forms. i.e. something like the following simplified code
where validation1() and validation(3) are server side validations using
ajax.

function save(){

// check validation one

if(!validation1()){

return false;

}

// check validation two

if(!validation2()){

return false;

}

// check validation three

if(!validation3()){

return false;

}

// validation passed so save

ajaxRequest(someUrl, someCallback);

}

Any advice appreciated.
Nov 21 '06 #1
1 1906

John Chan wrote:
Hi,

Im doing a maintenance application in ajax and coldfusion at work on IE6
exclusively. I have a save button on each form and i have to do various
validations server side and on client side when the user clicks save i.e
check that user exists in table, check users password is the same as
password in table, check password is valid, check that logged in user is a
super user etc etc to get the correct error message. Different forms may or
may not use all of these validations and not always in the same order. At
the moment for each form, im calling the first validation when user hits
save, then in that callback function im checking to see if its been
validated, if it has then run the next validation function and so on, so its
like a cascading effect. Is there a better way of doing this? so i can reuse
code on different forms. i.e. something like the following simplified code
where validation1() and validation(3) are server side validations using
ajax.

function save(){

// check validation one

if(!validation1()){

return false;

}

// check validation two

if(!validation2()){

return false;

}

// check validation three

if(!validation3()){

return false;

}

// validation passed so save

ajaxRequest(someUrl, someCallback);

}

Any advice appreciated.

Well, yes and no. You could go there and have your Ajax call do your
form validation when you click the save button, but then your problem
will be the time it takes for that call to go over the wire. So it
really depends on your (and more importantly, your users) connection
speed, but basically you're making 2 round-trips to the server for this
- the first (XMLHttpRequest with the entire form contents) taking a
second or two at least. The savings vs. reloading the page will be a
lot less than pure client-side validation.

I personally prefer to peg my Ajax validation calls to individual input
"blur" events. Once an input field loses focus (onblur), go ahead and
launch the XHR to validate the field while the user is typing in the
next field. Hopefully then the last field in your form will be an
optional one that doesn't require validation. In this manner, by the
time the user reaches the "Save" button, the validation will hopefully
be completed, and the total time spent will be little more than using
pure client-side validation.

Give that a try and let us know how it goes.

-David

Nov 21 '06 #2

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

Similar topics

1
by: Mihir | last post by:
Hi There, I've problem while I submit a button where I used AJAX, I created simple page which will search the customer name from database using AJAX. Once I search customer ID i need to search...
31
by: Tony | last post by:
I just noticed that prototype.js is one of the files in the Ajax.NET distribution - I'm pretty concerned about this. Does anyone know if this is the same "prototype.js" that is not well-liked...
1
by: AECL_DEV | last post by:
Hello Everyone, Ive seen alot of people saying that the best way to AJAX Validate a form is through the submit button, because validation should be synchronous. Im wondering, is there any good...
5
by: Martin | last post by:
Hello NG, I've been doing some AJAX for a few weeks now. The basics worked fine so far, but now I've got the following problem which I can't solve: With AJAX you typically update/replace only...
9
by: =?Utf-8?B?SGFyZHkgV2FuZw==?= | last post by:
Hi all, I followed first walk through sample from http://ajax.asp.net/docs/tutorials/IntroductionUpdatePanel.aspx to create my first testing page, The problem is after I clicked that botton, it...
5
by: lucyh3h | last post by:
Hi, I am trying to use XMLHttpRequest to do server side validation. I have several fields on a form and a submit button. The submit button has an event assocated with it when clicked. The...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
1
by: Mark B | last post by:
This is my first try at using AJAX. I want the calendars to be enabled if the user checks CheckBox1. It works OK for a normal all page refresh but once I introduced the AJAX code it stopped...
16
by: ashwinkumar18 | last post by:
hi, am very new to ajax and js . i tried using ajax for server validation in my jsp. i also used js for client side validation i have my js script for client side validation in a seperate file....
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.