hi guys...
i really need help on this one...

i try to put a form like this

<script>
function checkuser()
{
    var xmlhttp;
    if(window.XMLHttpRequest)
    {
        xmlhttp=new window.XMLHttpRequest(); //for mozilla  
    }
    else
    {
          try  
            {  
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");  
            }  
          catch (e)  
            {  
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");  
            } 
    }
    xmlhttp.onreadystatechange=function()
    {
        if(xmlhttp.readyState == 4 && xmlhttp.status ==200)
        {
            var response=xmlhttp.responseText;
            if (response="1"){
                return (true);
            }
            else{
                return (false);
            }
        }
    }
    var nocache = Math.random();
    xmlhttp.open("GET","file.php?nocache="+nocache,false);
    xmlhttp.setRequestHeader("content-type","application/x-www-form-urlencoded");
    xmlhttp.send(null);
}
</script>

<form method="post" action="somewhere.php" onSubmit="checkuser()">
<input type="submit" value="submit">
</form>

when i press submit button, i want to run a checking first whether it return true or false. if false, it won't go to "somewhere.php". but then the page keep going to somewhere.php even if it return false..

Recommended Answers

All 2 Replies

Try...

<form method="post" action="somewhere.php" onSubmit="return checkuser()">

oopss... i forgot to type "return" here...
but actually i hv fixed this problem ytd...
there is some mistake in the ajax part...
anw, thanks.. ^.^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.