{"id":1365,"date":"2022-08-30T15:15:55","date_gmt":"2022-08-30T15:15:55","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/13\/javascript-input-field-validation-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:15:55","modified_gmt":"2022-08-30T15:15:55","slug":"javascript-input-field-validation-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/javascript-input-field-validation-collection-of-common-programming-errors\/","title":{"rendered":"JavaScript Input Field Validation-Collection of common programming errors"},"content":{"rendered":"<p>If you open your browser&#8217;s console (F12 in Chrome and IE; ctrl-shift-K in FF) you&#8217;ll see that your code gives this error:<\/p>\n<pre><code>Uncaught ReferenceError: validationMessage is not defined \n<\/code><\/pre>\n<p>&#8230;because you declared the variable as <code>validMess<\/code>. Then in your update to the question you renamed it to <code>validMessage<\/code>. But still your other code is referring to <code>validationMessage<\/code>.<\/p>\n<pre><code>\/\/ WRONG:\nvar validMessage = \"Please correct the following errors: \\r\\n\";\n\n\/\/ RIGHT:\nvar validationMessage = \"Please correct the following errors: \\r\\n\";\n<\/code><\/pre>\n<p>Demo: http:\/\/jsfiddle.net\/JH8hg\/<\/p>\n<p><strong>UPDATE<\/strong> to go with your latest update:<\/p>\n<p>In your jsbin.com demo, you have attempted to add an <code>onsubmit<\/code> handler to a button:<\/p>\n<pre><code>\n<\/code><\/pre>\n<p>&#8230;but buttons don&#8217;t have an <code>onsubmit<\/code> event so this should be added to the form element:<\/p>\n<pre><code>  \n<\/code><\/pre>\n<p>And that form element doesn&#8217;t have a closing tag.<\/p>\n<p>And you forgot to give an <code>id=\"email\"<\/code> to your email field which means you got a JS error when you tried to use <code>document.getElementById('email').value.length<\/code>.<\/p>\n<p><strong>Working demo with those things fixed:<\/strong> http:\/\/jsbin.com\/ukepuh\/1\/edit<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-13 09:50:07. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>If you open your browser&#8217;s console (F12 in Chrome and IE; ctrl-shift-K in FF) you&#8217;ll see that your code gives this error: Uncaught ReferenceError: validationMessage is not defined &#8230;because you declared the variable as validMess. Then in your update to the question you renamed it to validMessage. But still your other code is referring to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1365","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1365","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1365"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1365\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1365"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1365"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1365"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}