Posted By:
Prissila_Aroul
Posted On:
Monday, June 19, 2006 03:38 AM
Hi, Im new to Ajax and trying to validate my form fields using client-side script and Ajax. Ajax is used to check if the fieldValue already exists . I want to return a value from the Ajax and use it to validate my form element. var returnResult = validateUsingAJAX(tableFieldId,f.fieldValue[i].value,i) ; i call a function validateUsingAJAX with respective parameters. function validateUsingAJAX(tableFieldId,val,indexValue){ var xmlHttpRequest=init(); xmlHttpRequest.open("GET", "/validateName.jsp?fieldValue="+val+"&tableFieldId="+tableFieldId, true); xmlHttpRequest.onreadystatechange=function() {alertContent
More>>
Hi,
Im new to Ajax and trying to validate my form fields using client-side script and Ajax. Ajax is used to check if the fieldValue already exists .
I want to return a value from the Ajax and use it to validate my form element.
var returnResult = validateUsingAJAX(tableFieldId,f.fieldValue[i].value,i) ;
i call a function validateUsingAJAX with respective parameters.
function validateUsingAJAX(tableFieldId,val,indexValue){
var xmlHttpRequest=init();
xmlHttpRequest.open("GET", "/validateName.jsp?fieldValue="+val+"&tableFieldId="+tableFieldId, true);
xmlHttpRequest.onreadystatechange=function() {alertContents(xmlHttpRequest)};
xmlHttpRequest.send(null)
}
function init(){
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
The function alertContents returns well the result "true" or "false".But when i return the res,nothing happens in the calling script ,coz its always undefined.
function alertContents(xmlHttpRequest){
if(xmlHttpRequest.readyState==4){
if(xmlHttpRequest.status==200){
var res = xmlHttpRequest.responseText; return res;
}
}
}
So,is a possible solution for this! Though it can be very simple, im finding it difficult to work on and stuck with it .
Thanks ,
<<Less