0

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!

1
  • I forgot to mention that the check works, it does show the alert but then still proceeds Commented Nov 2, 2013 at 10:30

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Hey dooxe, thank you, that solved! What a stupid mistake there. What threw me off was that the alert was actually displaying. Thanks a lot for your sharp eye!
1

Maybe you should use 'event.preventDefault();' instead of 'return false;'. in ie, you should use event.returnValue = false;.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.