Trying to create some form validation, running into a bump

Here is the URL
http://mesogom.com/gmjs/project2.html

The javascript isn’t validating the form. Something I am missing? Thanks.

Hi @garinwm, if you check the console you’ll see that none of your vendor scripts can be found and thus your scripts breaks as $ is not defined:

www.mesogom.com/gmjs…y.validate.min.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
www.mesogom.com/gmjs/js/jquery.min.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
www.mesogom.com/gmjs…y.validate.min.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
project2.html:11 Uncaught ReferenceError: $ is not defined
    at project2.html:11

Oh I forgot to write in the write dir for the js. Thanks.

But I fixed the links, what could be wrong now. I checked my console but I didn’t find anything.

Ah okay… well then the problem is that you put your script inside the head, and when the script gets executed, the #form element does not yet exist. So you either have to wrap the code in a $(document).ready() callback, or better yet, include it at the end of the page right before the closing </body> tag to guarantee that the DOM is fully loaded when the script runs.

Hey thanks for some reason didn’t realize it. I had it in the code at first but thought I didn’t need it. THanks again.

You mean $(document).ready()? Well you don’t – again, just put your script to the end of the page (along with jQuery etc.). This is preferable because this way, the browser doesn’t have to wait for those scripts to load until it can continue parsing the page, and the user can see the actual page content more quickly.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.