473,387 Members | 1,431 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.

Doubt in Ajax: get responseText in main function

i go tto perform some validation while ck=liking a button without refreshing the value.. i used ajax.My code is as follows...on button click i call the function validateGridAdd();
Inside tat function i need to call the function tat uses ajax to go to the server and come back.. the resultant value is to be obtained in the main function validateGridAdd().


Expand|Select|Wrap|Line Numbers
  1. //main function
  2. function validateGridAdd(a,rowNum){
  3.     var tForm = document.hallAllotFrm;
  4.         if(!validateCommon()){
  5.             return;
  6.         }
  7.  
  8.         getValidation();    
  9.     var length = document.getElementsByName("arrInv").length; 
  10.         var invArr = document.getElementsByName("arrInv");
  11.         var currInv = document.getElementById("arrInv0");
  12.         var currRel = document.getElementById("arrReliev3");
  13.  
  14.         if(currInv.value==currRel.value){
  15.             alert('Supervisor and  Relieving Faculty cannot be same person.');
  16.             return false;
  17.         }
  18.  
  19.         return true;
  20.     } 
  21.  
  22. //function for ajax
  23. function getValidation(){
  24.  
  25. var tForm = document.hallAllotFrm;
  26.  
  27.         var invig = document.getElementById("arrInv0").value;
  28.         var fromTime = document.getElementById("arrFrom1").value;
  29.         var toTime = document.getElementById("arrTo2").value;
  30.         var examDate = document.getElementById("date").value;
  31.  
  32.         var url = "validateSchedule.action?invigId=" + invig+""+'&fromTime='+fromTime
  33.          +""+'&toTime='+toTime+""+'&examDate='+examDate+""+'&flag='+flag;
  34.  
  35.  populateSelectBoxes(url);
  36.  
  37. }
  38.  
  39. function populateSelectBoxes(url){ 
  40.  
  41.         if (window.XMLHttpRequest) {
  42.                 req = new XMLHttpRequest();
  43.         } else if (window.ActiveXObject) {
  44.           req = new ActiveXObject("Microsoft.XMLHTTP");
  45.         }                                               
  46.         req.open("GET", url, true);
  47.         req.onreadystatechange = populateTextField;
  48.         req.setRequestHeader('Accept','message/x-jl-formresult');
  49.         req.send(null);  
  50. }
  51.  
  52. function populateTextField(){   
  53.     if (req.readyState == 4 && req.status == 200) {                 
  54.                  value=req.responseText;
  55.              if(value=="true"){
  56.                 alert("Supervisor scheduled for class.Please select another supervisor");
  57.                   document.getElementById("arrInv0").value=-1;
  58.                  } 
  59.        }
  60. document.getElementById("flag").value=value;
  61.     } 



ive got a hidden variable "flag" in my code.. tat variable is set to the responseText in my function. i need to get the responseText in my main function validateGridAdd(a,rowNum);
the value of flag can be eithr true or false.
How do i get this value in the main function.?
Jun 25 '07 #1
1 1803
acoder
16,027 Expert Mod 8TB
Once you've set the flag, it should be available in the main function though with the asynchronous nature of things, the question is when. The best thing would be to just put the code that depends on this variable setting in populateTextField().
Jan 17 '08 #2

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

Similar topics

4
by: Frances | last post by:
I literally started learning AJAX just last weekend.. I have this page, http://www.francesdelrio.com/ajax/db2.html, where I'm essentially doing what's here,...
17
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);"...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
2
by: mndprasad | last post by:
Hi friends, Am new to AJAX coding, In my program am going to have two texbox which going to implent AJAX from same table. One box is going to retrieve the value of other and vice...
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: 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
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...
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...

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.