By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,652 Members | 1,317 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,652 IT Pros & Developers. It's quick & easy.

From is going to submit even i keep return false in ajax

P: 13
Hi, This is prashanth kumar.
I am getting error , i am gettign number of records using ajax. Please solve this

if n >0 i am putting return false in response function.

but form is going to submit. i have no idea where to put retur false, using ajax.

my code is like ,


function checkValid(frm)
{

with(frm)
{
if(!checkValidNull(vCourseName,"Please Enter Course Name"))
return false;
if(!checkValidNull(vCourseCode,"Please Enter Course Code"))
return false;
if(!checkValidNull(dFee,"Please Enter Fee"))
return false;

var tmp_collegeId="";
var tmp_deselect="";
for(i=0;i<frm.iCollegeId.length;i++)
{
if(frm.iCollegeId[i].selected){
//alert(frm.iCollegeId[i].selected);
tmp_collegeId+=frm.iCollegeId[i].value+',';

}else tmp_deselect+=frm.iCollegeId[i].value+',';
}

var len=tmp_collegeId.length;
var len1=tmp_deselect.length;
tmp_collegeId=tmp_collegeId.substr(0,len-1);
tmp_deselect=tmp_deselect.substr(0,len1-1);
frm.collegeId1.value=tmp_collegeId;

if(frm.mode.value=='Update' && tmp_deselect !='')
{
document.getElementById('submitid').value="";
getCollege(frm.iCourseId.value,tmp_deselect);//here i am calling function for ajax
}


}
}


function getCollege(iCourseId,tmp_deselect)
{
var url =admin_url+"check_instructor.php?iCourseId="+iCour seId+'&tmp_deselect='+tmp_deselect;
var isWorking = false;
if (!isWorking)
{
//catID = course;
isWorking = true;
//url += catID;
//alert(url);
if (window.XMLHttpRequest)
{
http_state_Member=new XMLHttpRequest()
http_state_Member.open("GET",url, true);
http_state_Member.onreadystatechange=handleHttpRes ponseStateMember
http_state_Member.send(null)

}

// code for IE
else if (window.ActiveXObject)
{
http_state_Member=new ActiveXObject("Microsoft.XMLHTTP")
if (http_state_Member)
{
http_state_Member.open("GET",url, true);
http_state_Member.onreadystatechange=handleHttpRes ponseStateMember
http_state_Member.send()

}
}
//return false;
}//end if(!working))
//if(!displayPopup) closeLoadingWindow(winObj);
}//end functiongetStateName()

function handleHttpResponseStateMember()
{
var temp;
var tmp_color;//alert(http_state_Member.readyState);
if (http_state_Member.readyState == 4)
{
var xmlDocument = http_state_Member.responseXML;
var no = xmlDocument.getElementsByTagName('tot').item(0).fi rstChild.data;
//alert(no);
if(no>0)
{
alert("Please Change the Instructor Details First ,Which are using Deselected Colleges ");
return false;

}
}

}
Jun 27 '07 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
In Ajax, the request is made and then it goes about its business. When the response returns, then your handleResponse function will run. In the meantime, the form has already been submitted.

To avoid this, keep this Ajax function out of the validate function which you're probably running onsubmit. I am assuming that iCollegeID is a set of checkboxes, so you could check for this when a checkbox is clicked. Alternatively, just check for this on the server-side.
Jun 27 '07 #2

Post your reply

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