javascript - JSHint "not defined" errors -
i have function i'm using validate contact form, getting ton of "not defined" errors when run through jshint. quite jquery noob , i' not sure how these supposed defined.
(function ($, document, undefined) { $(document).ready(function(){ // place id's of required fields here. required = ["name", "email", "message"]; // if using id other #email or #error replace here email = $("#email"); errornotice = $("#error"); // text show within field when incorrect emptyerror = "please fill out field."; emailerror = "please enter valid e-mail."; $("#theform").submit(function(){ //validate required fields (i=0;i<required.length;i++) { var input = $('#'+required[i]); if ((input.val() == "") || (input.val() == emptyerror)) { input.addclass("needsfilled"); input.val(emptyerror); errornotice.fadein(750); } else { input.removeclass("needsfilled"); } } // validate e-mail. if (!/^([a-za-z0-9_\.\-])+\@(([a-za-z0-9\-])+\.)+([a-za-z0-9]{2,4})+$/.test(email.val())) { email.addclass("needsfilled"); email.val(emailerror); } //if inputs on page have class 'needsfilled' form not submit if ($(":input").hasclass("needsfilled")) { return false; } else { errornotice.hide(); return true; } }); // clears fields in form when user clicks on them $(":input").focus(function(){ if ($(this).hasclass("needsfilled") ) { $(this).val(""); $(this).removeclass("needsfilled"); } }); }); })(jquery, document);
here couple examples:
from form data - 'required' not defined.
required = ["name", "email", "message"];
'i' not defined.
for (i=0;i<required.length;i++) {
and 'email' not defined.
if (!/^([a-za-z0-9_\.\-])+\@(([a-za-z0-9\-])+\.)+([a-za-z0-9]{2,4})+$/.test(email.val())) {
you should define variables "var":
var required = ["name", "email", "message"]; for(var i...
Comments
Post a Comment