0

I'm trying to figure out why my code is not triggering past a certain point. In the below code the alert for Luhn is displaying fine but it appears to not progress past that. So it appears i am successfully passing the number from the onclick method but the function is not running because i'm not getting a true or false alert based on the rule set.

Any help appreciated

Thanks

<html>

<head>
    <script type="text/javascript">
        function Validate(Luhn) {
            alert(Luhn);
            var LuhnDigit = parseInt(Luhn.substring(Luhn.length - 1, Luhn.length));
            var LuhnLess = Luhn.substring(0, Luhn.length - 1);
            if (Calculate(LuhnLess) == parseInt(LuhnDigit)) {
                alert("True");
                return true;
            }
            alert("False");
            return false;
        }
    </script>
</head>

<body>
    <form>
        <input type="form" id='fv'>
        <input type="button" onclick="Validate('4111111111111111')" value="Call function">

    </form>

</body>

</html>
2
  • 1
    You know you're not an experienced Javascript programmer when... you name your functions with a capitalized word :) Commented Jun 5, 2014 at 7:04
  • Sprung :) We all start somewhere :) Commented Jun 5, 2014 at 11:09

1 Answer 1

1

The statement after return wont execute and execution control is immediately transferred to calling function. Put alert before return statement. You can read more about return here.

if (Calculate(LuhnLess)==parseInt(LuhnDigit))
{
    alert("True");
    return true;

}   

alert("False");
return false;
Sign up to request clarification or add additional context in comments.

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.