473,543 Members | 3,588 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Doubt in Ajax: get responseText in main function

58 New Member
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.         }
  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");
  14.         if(currInv.value==currRel.value){
  15.             alert('Supervisor and  Relieving Faculty cannot be same person.');
  16.             return false;
  17.         }
  19.         return true;
  20.     } 
  22. //function for ajax
  23. function getValidation(){
  25. var tForm = document.hallAllotFrm;
  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;
  32.         var url = "validateSchedule.action?invigId=" + invig+""+'&fromTime='+fromTime
  33.          +""+'&toTime='+toTime+""+'&examDate='+examDate+""+'&flag='+flag;
  35.  populateSelectBoxes(url);
  37. }
  39. function populateSelectBoxes(url){ 
  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. }
  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 1814
16,027 Recognized Expert Moderator MVP
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 populateTextFie ld().
Jan 17 '08 #2

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

Similar topics

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, http://www.w3schools.com/ajax/ajax_source.asp, only my array is populated from info pulled from db.. I added interface to HTML interface to insert info into db; info gets inserted in to db...
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);" onclick="show('ajaxrequest.php?action=removefield','div1');show('ajaxrequest.php?action=reloaddiv2','div2')">verwijderen</a> While both seperate actions work they dont when I put them together. Anyone know how to fix this ? My ajax.js with funcition...
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 i change something in php file using in ajax function.it not refreshed,means its shows the previous result it not get updated.i can't understand...
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 versa. I have implemented successfully for one text box, but it's done for the other field, since am getting script errors. <script> var...
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...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
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...
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...
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...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
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...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.