简体   繁体   中英

SyntaxError-Unexpected End of Input

I'm a newbie. Just coded a simple loan approval application using Javascript with Jquery and Jquery Validation plugins. I'm getting a SyntaxError. - I've matched the beginning and end parens, curly brackets, semicolons and commas and don't understand why its not working. - I've tried different variations and keep getting the error (it points to different code lines with each change). - When I comment out the jQuery Validation code it works so the issue must be with the jQuery Validation code.

Below is code. Currently getting SyntaxError on line 61 which is the last line reflecting --> });

// JavaScript Document // DIAMOND LENDING BANK LOAN APPLICATION

$(document).ready(function() {
    $("#submit").click(function() {
    var salary =  $("#salary").val();   // get salary
    var creditScore = $("#creditScore").val(); // get creditScore
    var monthsJob = $("#monthsJob").val(); // get months at job

    if  (salary >= 40000 && creditScore >= 600) {
        $("#decision").html("Your loan is approved!")
    }
    else if (salary >= 40000 && monthsJob >= 12) {
        $("#decision").html("Your loan is approved!")
    }
    else if (creditScore >= 600 && monthsJob >= 12) {
        $("#decision").html("Your loan is approved!")
    }
    else {
        $("#decision").html("Your loan is declined.")
    };
    return false;
    }); // closes submit.click  

    //     J Q U E R Y    V A L I D A T O R
    $("#loanApp").validate({
        rules: {
            salary: {
            required: true,
            rangelength: [4, 10],
            number: true
            },
            creditScore: {
            required: true,
            rangelength: [3, 3],
            number: true
            },
            monthsJob: {
            required: true,
            rangelength: [1, 3], 
            number: true
            },  
            messages: {
            salary: {
            required: "Please enter your salary.",
            rangelength: "Enter at least 4 numbers and up to 10.",
            number: "Enter numbers only."
            },
            creditScore: {
            required: "Please enter your Credit Score.",
            rangelength: "Credit Scores are 3 numbers long.",
            number: "Enter numbers only."
            },
            monthsJob: {
            required: "Please enter your months at current job.",
            rangelength: "Enter at least 1 number and up to 3.",
            number: "Enter numbers only."
            }
        } 
    }
});

You lack another }); at the very end for your $(document).ready(... . The current one is for the $(#loanApp).validate(...

You've made a little indentation error, which caused you to miss a curly brace for your document.ready() :

            }
        } 
    }
});

Should be:

                }
            } 
        }
    });
});

You're missing an extra }); at the end there. Add that and everything should work fine.

 $(document).ready(function() { $("#submit").click(function() { var salary = $("#salary").val(); // get salary var creditScore = $("#creditScore").val(); // get creditScore var monthsJob = $("#monthsJob").val(); // get months at job if (salary >= 40000 && creditScore >= 600) { $("#decision").html("Your loan is approved!") } else if (salary >= 40000 && monthsJob >= 12) { $("#decision").html("Your loan is approved!") } else if (creditScore >= 600 && monthsJob >= 12) { $("#decision").html("Your loan is approved!") } else { $("#decision").html("Your loan is declined.") }; return false; }); // closes submit.click // JQUERYVALIDATOR $("#loanApp").validate({ rules: { salary: { required: true, rangelength: [4, 10], number: true }, creditScore: { required: true, rangelength: [3, 3], number: true }, monthsJob: { required: true, rangelength: [1, 3], number: true }, messages: { salary: { required: "Please enter your salary.", rangelength: "Enter at least 4 numbers and up to 10.", number: "Enter numbers only." }, creditScore: { required: "Please enter your Credit Score.", rangelength: "Credit Scores are 3 numbers long.", number: "Enter numbers only." }, monthsJob: { required: "Please enter your months at current job.", rangelength: "Enter at least 1 number and up to 3.", number: "Enter numbers only." } } } }); });//this is missing from your code, add this 

Missing a }); at the end.

Looks like the missing tab between messages and salary is messing you up from a visual perspective.

$(document).ready(function() {
    $("#submit").click(function() {
    var salary =  $("#salary").val();   // get salary
    var creditScore = $("#creditScore").val(); // get creditScore
    var monthsJob = $("#monthsJob").val(); // get months at job

    if  (salary >= 40000 && creditScore >= 600) {
        $("#decision").html("Your loan is approved!")
    }
    else if (salary >= 40000 && monthsJob >= 12) {
        $("#decision").html("Your loan is approved!")
    }
    else if (creditScore >= 600 && monthsJob >= 12) {
        $("#decision").html("Your loan is approved!")
    }
    else {
        $("#decision").html("Your loan is declined.")
    };
    return false;
    }); // closes submit.click  

    //     J Q U E R Y    V A L I D A T O R
    $("#loanApp").validate({
        rules: {
            salary: {
            required: true,
            rangelength: [4, 10],
            number: true
            },
            creditScore: {
            required: true,
            rangelength: [3, 3],
            number: true
            },
            monthsJob: {
            required: true,
            rangelength: [1, 3], 
            number: true
            },  
            messages: {
                salary: {
                required: "Please enter your salary.",
                rangelength: "Enter at least 4 numbers and up to 10.",
                number: "Enter numbers only."
                },
                creditScore: {
                required: "Please enter your Credit Score.",
                rangelength: "Credit Scores are 3 numbers long.",
                number: "Enter numbers only."
                },
                monthsJob: {
                required: "Please enter your months at current job.",
                rangelength: "Enter at least 1 number and up to 3.",
                number: "Enter numbers only."
                }
            } 
        }
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM