0

I have a bit of javascript that I am trying to untangle, it's on a PHP form to calculate mortgage repayments, but clicking the calculate button does nothing.

Looking at Chrome Console I get the message

Uncaught TypeError: Undefined is not a function" on line 10($("#form_7") to 19

of the following code.

<script type="text/javascript">
    $(document).ready(function() {
        $("a.ActiveButton").bind({
            mousedown:function(){
                if ($(this).attr('disabled') === undefined ) 
                    $(this).addClass('Activated');
            }, 
            mouseleave:function(){ 
                if ($(this).attr('disabled') === undefined ) 
                    $(this).removeClass('Activated');
            }, 
            mouseup:function(){ 
                if ($(this).attr('disabled') === undefined ) 
                    $(this).removeClass('Activated');
            }
        });

        $("#form_7").validate({ 
            onkeyup: false, 
            showErrors: function(errorMap, errorList) { 
                if (errorList.length) alert(errorList[0].message); 
            }, 
            onclick: false, 
            rules: { 
                'Property_Price': { number: true } , 
                'Deposit': { number: true } , 
                'Duration': { number: true } , 
                'InterestRate': { number: true }  
            }, 
            onfocusout: false, 
            messages: { 
                'Property_Price': { number: "Please enter the property purchase price." } , 
                'Deposit': { number: "Please enter your deposit amount or 0 if there is no deposit." } , 
                'Duration': { number: "Please enter the duration of the mortgage." } , 
                'InterestRate': { number: "Please enter the mortgage interest rate." }  
            } 
        });

        $('#btn_4').click( function(){validate_form_7( form_7 )});
    });
</script>

Does anyone know what is causing this error and how it can resolved?

6
  • I dont think you have imported jquery Commented Nov 25, 2014 at 12:39
  • That's possible, but usually in that case the error message is: Uncaught ReferenceError: $ is not defined. Commented Nov 25, 2014 at 12:41
  • jQuery is probably there, but the validate pluging probably isn't. Commented Nov 25, 2014 at 12:44
  • Did your calculate button is the one with id #btn_4? If yes, then you are probably getting error on function validate_form_7(). Commented Nov 25, 2014 at 12:44
  • I think there's a required argument somewhere in the options, which you are not supplying, hence it's undefined and the error comes from inside validation plugin. Commented Nov 25, 2014 at 12:45

2 Answers 2

1

It looks like you don't have validate defined.

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

Comments

0

The answer is that your code is trying to dereference as a function something, that isn't one.

Try enabling stop-on-exception mode in your browser and see what "function" your code is trying to call when it crashes. Once you have a stack trace, it will be easier both for you to figure out, and for us to help.

Off-hand, I do not see any issues with the provided code.

3 Comments

Teaching how to debug doesn't provides the answer, as well.
@DontVoteMeDown Give a man fire and he will be warm for one night. Teach a man to light it, and he will be warm for all his life. Besides, it can be improved with additional information, and it's a second-best alternative to nothing at all - or to snide comments.
Sure, the debug part is relevant, but it still doesn't answer. I mean, a real solution with all debug advising would be perfect.

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.