473,396 Members | 2,082 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,396 software developers and data experts.

Form validation using AJAX

rizwan6feb
108 100+
Hi, everyone! I am learning AJAX these days. I want to validate a form with Ajax in such a way that every field is validated on the "onBlur" event. There are fields like Username, First Name, Last Name, Email, Password etc in the form. When the user changes focus from Username to any other field, Username is validated, and other fields are validated the same way.
How do i do this?
The technique that i have used only works if the user doesn't changes the focus too quickly, otherwise some fields show processing icon infinitly and only the last field gets validated.
Jun 2 '08 #1
3 1999
gits
5,390 Expert Mod 4TB
i guess you are using a global request-object and loose the reference when you start (in fact overwrite that reference) a new request from another field ... try to keep the references in an array or object ...

show how you use the request object in case you have problems to implement the suggestion ...

kind regards
Jun 2 '08 #2
rizwan6feb
108 100+
The code for sending a validation request to check.php is given below
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2.     var ajaxRequest;  // The variable that makes Ajax possible!
  3.     var f1;
  4. <!-- 
  5. //Browser Support Code
  6. function getAjaxObject(){
  7.     try{
  8.         // Opera 8.0+, Firefox, Safari
  9.         ajaxRequest = new XMLHttpRequest();
  10.     } catch (e){
  11.         // Internet Explorer Browsers
  12.         try{
  13.             ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
  14.         } catch (e) {
  15.             try{
  16.                 ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
  17.             } catch (e){
  18.                 // Something went wrong
  19.                 alert("Your browser broke!");
  20.                 return false;
  21.             }
  22.         }
  23.     }
  24.     return ajaxRequest;
  25. }
  26.  
  27. function sendRequest(a,text){
  28.         f1 = document.getElementById('chk'+a);
  29.         f1.style.display='none';
  30.         var e1=document.getElementById('checking'+a);
  31.         e1.style.display='';
  32.  
  33. ajaxRequest=getAjaxObject();
  34. ajaxRequest.open("GET", "check.php?cid="+text+"&c1="+a, true);
  35. ajaxRequest.send(null);
  36.  
  37. ajaxRequest.onreadystatechange = function(){
  38.     if(ajaxRequest.readyState==4){
  39.  
  40.         var f=document.form1;
  41.         e1.style.display='none';
  42.         f1.style.display='';
  43.         f1.innerHTML = ajaxRequest.responseText;
  44.  
  45.     }
  46. }
  47. }
  48.  
Where should i use object or Array?
I have used the variable "ajaxRequest" as array but it doesn't work
Jun 2 '08 #3
gits
5,390 Expert Mod 4TB
let me give you a basic idea:

Expand|Select|Wrap|Line Numbers
  1. // global array for your requests
  2. var requests = [];
  3.  
  4. function get_request_obj() {
  5.     var req_obj = null;
  6.  
  7.     // typical code but use the private
  8.     // var req_obj here and return that
  9.     // at least
  10.  
  11.     return req_obj;
  12. }
  13.  
  14. function send_request() {
  15.     // now we fill the requests-array everytime with 
  16.     // a new request
  17.     requests[requests.length] = get_request_obj();
  18.  
  19.     // now use this reference from here: requests[requests.length]
  20.     // this is the last initialized request and the ref is stored
  21. }
  22.  
additional to this you may want to delete the reference when a request is completed ...

kind regards
Jun 2 '08 #4

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

Similar topics

4
by: josh.dutcher | last post by:
I'm trying to set up a simple "change your password" form. I've got an AJAX process that is checking the new password the user enters against their current password to make sure they're changing...
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...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
5
by: Advo | last post by:
Basically, im redesigning a form page on our website. Currently the user submits the form, it does a few javascript checks and either submits to the "processstuff.php" page, or gives the user a...
3
by: mark4asp | last post by:
How can I stop my Calendar control from firing the form validation events? I have a form containing several controls which have several validation controls each. One control is a TextBox...
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
2
by: Ronald Raygun | last post by:
I have a form that I am using as a wizard. The wizard comprises of several forms contained in divs, which are hidden/made visible, depending on the wizard step. Each form has an action parameter...
3
pradeepjain
by: pradeepjain | last post by:
hii guys , I wanna share a very gud ajax validation script with php... Ajax Form Validation - sForm | chains.ch weblog I am very new to ajax .So i wanna small help....i want to...
2
scubak1w1
by: scubak1w1 | last post by:
Hello, I am building a form that collects some data about a file and throws it into a PosgreSQL database and also allows the user to upload and process the file using PHP's $_FILES... i.e.,...
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
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?
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...
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
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...
0
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...
0
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,...

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.