473,624 Members | 2,577 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(som eUrl, someCallback);

}

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

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(som eUrl, 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
5786
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 order related to that customers. So on my page I've Search Button(Image Button).. Now if I click on search button without selecting the customer from the result which I get from AJAX method then it will work fine but if I select a customer ID from...
31
3108
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 around here? If so, do you know if Ajax.NET can be used without prototype.js? -- "The most convoluted explanation that fits all of the made-up facts is the most likely to be believed by conspiracy theorists. Fitting the
1
1864
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 way to validate a form field by field like AJAX would do, but to keep it synchronous? i.e. one action, one validation. Thanks,
5
2207
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 parts of your page. But in my application there are situation when I first notice on the server -- so AFTER sending an AJAX request -- that I have to update the complete page instead of only some parts. And what do I do now???
9
1866
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 still trigged a postback. Do I miss something? Following is my code: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
5
3215
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 javascript method will do the form validation for each field one by one. For each field, an XMLHttpRequst will be made to a PHP file and get the return, either set an error field (<span>'s innerHTML) or leave it empty. Then I'll check the error field...
7
3599
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
2044
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 working. Any ideas? <%@ Page Language="VB" AutoEventWireup="false" CodeFile="default-ajax.aspx.vb" Inherits="pages_verify_groups_Default" Debug="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
16
2192
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. i embedded the ajax code in the jsp itself. the client side validation and the ajax code are working when i use them seperately. but when i try to use them both , the client side validation is not taking place at all. my page is directly...
0
8249
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
8179
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
8633
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...
1
8348
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7176
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...
0
4084
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...
0
4187
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2613
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

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.