Either post the code or a link to a test page.
Hi,
Here is the Ajax code..
-
<!-- Function for HTTPRequest object-->
-
function getHTTPObject()
-
{
-
var xmlhttp;
-
if (window.ActiveXObject)
-
{
-
try
-
{
-
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
-
}
-
catch (e)
-
{
-
try
-
{
-
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
catch (E)
-
{
-
xmlhttp = false;
-
}
-
}
-
}
-
else
-
{
-
xmlhttp = false;
-
}
-
if (window.XMLHttpRequest)
-
{
-
try
-
{
-
xmlhttp = new XMLHttpRequest();
-
}
-
catch (e)
-
{
-
xmlhttp = false;
-
}
-
}
-
return xmlhttp;
-
}
-
-
<!-- Function for checking duplicate names....-->
-
function validatenames()
-
{
-
var htpobj = getHTTPObject();
-
var str = document.mod_form.Mod_Name.value;
-
var pname=document.mod_form.Prod_Name.value
-
url='checknames.php?mname='+str+'&pname='+pname;
-
htpobj.open("GET", url, false);
-
htpobj.onreadystatechange = function()
-
{
-
if (htpobj.readyState == 4)
-
{
-
if(htpobj.responseText == 1)
-
{
-
alert(htpobj.responseText);
-
document.getElementById('vlnames').value=0;
-
document.mod_form.Mod_Name.focus();
-
-
}
-
else
-
{
-
document.getElementById('vlnames').value=1;
-
alert(htpobj.responseText);
-
document.mod_form.Mod_Desc.focus();
-
}
-
}
-
}
-
htpobj.send(null);
-
}
-
Here is where i'm calling it....
-
<!-- Function for checking blank fields....-->
-
function validate_form()
-
{
-
validatenames();
-
//document.write(document.feat_tab.width);
-
tr=true;
-
if(document.mod_form.Prod_Name.value == "")
-
{
-
tr = false;
-
alert('Product Id blank');
-
return tr;
-
}
-
else if(document.mod_form.Mod_Name.value == "")
-
{
-
tr = false;
-
alert('Module Name Field Can\'t Be Blank');
-
return tr;
-
}
-
else if(document.mod_form.vlnames.value==0)
-
{
-
tr=false;
-
alert('Duplicate Module Name Is Not Allowed');
-
document.mod_form.Mod_Name.focus();
-
return tr;
-
}
-
else
-
{
-
var agre=confirm('are you sure you want to submit the data???') ;
-
if(!agre) return false;
-
else
-
{
-
//refresh_feat_frame();
-
return true;
-
}
-
}
-
-
}
-
And my PHP script just returns 0 and 1 if the name i'm sending to the scipt is present in database or not......
Now upto this point what i've done and what problem i've faced.....
As you can see i'm giving Ajax response to one TEXT field which i'm checking in form validation function.. If it has 0 then duplicate name is entered and if it is 1 then it means that user can submit the value.
Now first i tried the VALIDATENAMES() function itself in IF condition but as i didnt know how return something from Ajax function it was not working(If you can help me with that that would be good as well).
So what i did is i'm giving Ajax response to one textbox and then checking it for validation purpose.. Now what my problem is.....
I'm using firebug for javascrip/Ajax debugging.... now i've checked following four cases..
FireBug Enabled-Synchronuous Request
FireBug Disabled-Synchronuous Request
FireBug Enabled-Asynchronuous Request
FireBug Disabled-Asynchronuous Request
- Late response in both cases
One more thing i've learned through googling is this happens if you've not used your Ajax functions properly.... So in the last i would like to mention that what i want to do so if there is any another way you can guide me there...
Here i'm checking users input(name). If it is already there in database user will not be allowed to submit and if it is not there user can enter the value.....
Regards,
RP