Reputation: 461
I'm using javascript for form validation but after submitting and the code returning false the form still submits. I used the 'fixes' in other topics I found but the form still submits.
Here is my code:
function CheckFormi() {
var lh = document.getElementById('op').value;
var ph = document.getElementById('oc').value;
var lb = document.getElementById('dp').value;
if (lh == "País" || ph == "Codiga postal" || lb == "País") {
if (lf == "País") {
document.getElementById('op').style.border = "solid 1px #FF0000";
}
if (ph == "Codiga postal") {
document.getElementById('oc').style.border = "solid 1px #FF0000";
}
if (lb == "País") {
document.getElementById('dp').style.border = "solid 1px #FF0000";
}
alert('error');
return false;
} else {
document.getElementById('a').submit();
}
}
This is how I call the function:
<form action="processor.php" method="post" id="a" onsubmit="return CheckFormi()">\
Any help will be appreciated,
thanks in advance!
Upvotes: 0
Views: 5127
Reputation: 99
Maybe you should use 'event.preventDefault();' instead of 'return false;'. in ie, you should use event.returnValue = false;.
Upvotes: 1
Reputation: 1490
You have an error at this line :
if (lf == "País") {
variable lf
may not exist (lh
may be ?). That could explain why your alert is not displayed.
Upvotes: 1