{"id":5702,"date":"2013-12-25T05:02:13","date_gmt":"2013-12-24T18:02:13","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=5702"},"modified":"2013-12-25T05:02:13","modified_gmt":"2013-12-24T18:02:13","slug":"javascript-form-required-fields-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-form-required-fields-primer-tutorial\/","title":{"rendered":"Javascript Form Required Fields Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Javascript\/FormFieldRequired\/\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"Javascript Form Required Fields Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Javascript\/FormFieldRequired\/FormRequiredFields.jpg\" title=\"Javascript Form Required Fields Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Javascript Form Required Fields Primer Tutorial<\/p><\/div>\n<p>In tutorial here we use Javascript code to validate an HTML form element&#8217;s input tag data for Required Fields as a follow up to previous <a  title='Javascript Form Validation Primer Tutorial' href='#jfvpt'>Javascript Form Validation Primer Tutorial<\/a> as shown below.  This tutorial&#8217;s methods differ in that the GET parameters are not used, so the page calls itself via a form action # (ie. call yourself), for the validation and the input tag classname is manipulated to do the job.    Specifically, fields designated with a classname of <i>needed<\/i> are scrutinized and if not filled out will have an additional classname of <i>error<\/i> tagged on (pardon the pun &#8230; oh, it&#8217;s so punny &#8230; chortle, chortle).   So we end up not succeeding if elements end up with a classname of <i>error<\/i> involved with them.  Also, some CSS is used to flag the offending field (though you can go &#8220;oh, you offensive field&#8221; if you like, during the live run you can do by clicking the picture above).  The convention to put * somewhere on the corresponding label tag is used here, but different methods are used on the web to flag that a field might be mandatory (or required).   In today&#8217;s tutorial that required field is an email address and a rudimentary technique not involving regular expressions is used to only assure that a @ is present in the field, as well as it <a target=_blank title='Being There' href='http:\/\/www.youtube.com\/watch?v=FcPQ9gww_qc'><i>being there<\/i><\/a>.<\/p>\n<p>Regarding this topic I really like <em>&#8220;JavaScript &amp; Ajax&#8221; seventh edition by Tom Negrino and Dori Smith<\/em>.<\/p>\n<p>\nDownload programming source code and rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/Javascript\/FormFieldRequired\/form_field_required.html_GETME'>form_field_required.html<\/a><\/p>\n<hr \/>\n<p id='jfvpt'>Previous <a target=_blank title='Javascript Form Validation Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=1431'>Javascript Form Validation Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Javascript\/FormValidation\/validate.html\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"Javascript Form Validation Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Javascript\/FormValidation\/Form_Validation_Primer.jpg\" title=\"Javascript Form Validation Primer Tutorial\" \/><\/a><p class=\"wp-caption-text\">Javascript Form Validation Primer Tutorial<\/p><\/div>\n<p>In tutorial here we use Javascript code to validate an HTML form element&#8217;s input tag data using regular expressions, as described by <a target=_blank title='Regular expressions' href='http:\/\/en.wikipedia.org\/wiki\/Regular_expression'>Wikipedia<\/a> below:<\/p>\n<blockquote><p>In computing, a regular expression (abbreviated regex or regexp) is a sequence of text characters, some of which are understood to be metacharacters with symbolic meaning, and some of which have their literal meaning, that together can automatically identify textual material of a given pattern, or process a number of instances of it that can vary from a precise equality to a very general similarity of the pattern. The pattern sequence itself is an expression that is a statement in a language designed specifically to represent prescribed targets in the most concise and flexible way to direct the automation of text processing of general text files, specific textual forms, or of random input strings. A regular expression patterns a match to a string. It is employed in a search to identify text for further processing, such as displaying the match, or altering it; or it is employed to simply inform of the location or count. The concept arose in the 1950s, when Kleene formalized the description of a regular language, and came into common use with the Unix text processing utilities ed, an editor, and grep (global regular expression print), a filter.<\/p><\/blockquote>\n<p>This Javascript form validation client-side technique uses a GET method, but if you want to hide your data and use a POST method, you may need to do form validation from the server-side using  <a target=_blank title='Alternate Javascript client-side Form Validation via GET method' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=1440'>PHP<\/a> , for example.<\/p>\n<p>By the way the format of the telephone number asked for by this tutorial is for an Australian telephone number which is a 2 or 3 digit area code followed by an 8 digit number.   If you can&#8217;t get through maybe you can just listen to a <a target=_blank title=\"Ring, Ring, Why don't you give me a call\" href='http:\/\/www.youtube.com\/watch?v=-aRBqoZN9rA'>song<\/a>.<\/p>\n<p><a target=_blank href='http:\/\/www.rjmprogramming.com.au\/Javascript\/FormValidation\/validate.html_GETME'>Download programming source code and rename to validate.html<\/a><\/p>\n<p>Regarding this  <a target=_blank title='click picture' href='http:\/\/www.rjmprogramming.com.au\/Javascript\/FormValidation\/validate.html'>topic<\/a> I really like <em>&#8220;JavaScript &amp; Ajax&#8221; seventh edition by Tom Negrino and Dori Smith<\/em> <\/p>\n<p><strong><em>Did you know &#8230;<\/em><\/strong><br \/>\nJavaScript makes a great easy-access Calculator?<\/p>\n<p>Try typing the lines below into the address bar of your favourite browser:<\/p>\n<p>Javascript: eval(512 \/ 380);<br \/>\nJavascript: eval(512 * 380);<br \/>\nJavascript: eval(512 &#8211; 380);<br \/>\nJavascript: eval(512 + 380);<br \/>\nJavascript: eval(512 % 380);<\/p>\n<p>These days we spend so much time on the Internet it is a much quicker way to get to a calculator!\n<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d1431' onclick='var dv=document.getElementById(\"d1431\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=Javascript\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d1431' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d5702' onclick='var dv=document.getElementById(\"d5702\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?s=Javascript\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d5702' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In tutorial here we use Javascript code to validate an HTML form element&#8217;s input tag data for Required Fields as a follow up to previous Javascript Form Validation Primer Tutorial as shown below. This tutorial&#8217;s methods differ in that the &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-form-required-fields-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,37],"tags":[281,453,576,652,997,1040,1056,1319],"class_list":["post-5702","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-css","tag-form-validation","tag-html","tag-javascript","tag-programming","tag-regex","tag-required-fields","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/5702"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=5702"}],"version-history":[{"count":0,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/5702\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=5702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=5702"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=5702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}