I'm trying to validate a form, and if it is valid then go to another URL using location.href. My problem is that sometimes it submits the page instead of using location.href, which I don't want it to do.
I'm calling it in the form tag using:
ONSUBMIT="checkLogin(this); return document.returnValue;"
Here's the script:
<SCRIPT LANGUAGE="JavaScript">
<!--//
// Form field values to check against
var vUserName = "Joe Shmoe";
var vPass = "";
// Where to next?
var vNext = "
// Set default Error variable
var vErrors = "";
// Check form
function checkLogin(vForm){
// If the username is correct, go to the next page
if(vForm.fUserName.value == vUserName){
location.href = vNext;
vErrors = "";
}else{
// Set the error to wrong
vErrors = "wrong";
}
// set the return variable
document.returnValue = (vErrors == '');
}
//-->
</SCRIPT>
I'm calling it in the form tag using:
ONSUBMIT="checkLogin(this); return document.returnValue;"
Here's the script:
<SCRIPT LANGUAGE="JavaScript">
<!--//
// Form field values to check against
var vUserName = "Joe Shmoe";
var vPass = "";
// Where to next?
var vNext = "
// Set default Error variable
var vErrors = "";
// Check form
function checkLogin(vForm){
// If the username is correct, go to the next page
if(vForm.fUserName.value == vUserName){
location.href = vNext;
vErrors = "";
}else{
// Set the error to wrong
vErrors = "wrong";
}
// set the return variable
document.returnValue = (vErrors == '');
}
//-->
</SCRIPT>