{"id":883,"date":"2012-09-17T10:17:01","date_gmt":"2012-09-17T10:17:01","guid":{"rendered":"http:\/\/www.withinweb.com\/info\/?p=883"},"modified":"2012-09-17T10:17:01","modified_gmt":"2012-09-17T10:17:01","slug":"a-simple-javascript-submit-and-validation-example","status":"publish","type":"post","link":"https:\/\/www.withinweb.com\/info\/a-simple-javascript-submit-and-validation-example\/","title":{"rendered":"A simple Javascript Submit and Validation example"},"content":{"rendered":"<p>The following HTML script illustrates a simple Javascript validation and submit script that checks inputs on the PC before it is submitted to the server.\u00a0 You might use this method on a web site before submission to the PHP script.\u00a0 The Javascript displays a nice error message on submission if there are any errors and it is quite easy to add more tests when other text boxes are added.<\/p>\n<blockquote><p>&lt;!DOCTYPE html PUBLIC &#8220;-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN&#8221; &#8220;http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd&#8221;&gt;<br \/>\n&lt;html xmlns=&#8221;http:\/\/www.w3.org\/1999\/xhtml&#8221;&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text\/html; charset=utf-8&#8243; \/&gt;<br \/>\n&lt;title&gt;Submit a form using Javascript with input validation&lt;\/title&gt;<\/p>\n<p>&lt;script language=&#8221;javascript&#8221; type=&#8221;text\/javascript&#8221;&gt;<br \/>\n&lt;!&#8211;<\/p>\n<p>\/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n\/\/Javascript that will submit the form when all entries are valid<br \/>\nfunction button_onclick(frmCreate) {<\/p>\n<p>var themessage = &#8220;Error in entries : &#8220;;<br \/>\nvar isOK = true;<\/p>\n<p>if ( frmCreate.txtItem_Number.value == &#8220;&#8221; ) {<br \/>\nthemessage = themessage + &#8220;\\n&#8221; + &#8220;* Enter PayPal item code&#8221;;<br \/>\nisOK = false;<br \/>\n}<\/p>\n<p>if ( frmCreate.txtItem_Name.value == &#8220;&#8221; ) {<br \/>\nthemessage = themessage + &#8220;\\n&#8221; + &#8220;* Enter PayPal item name&#8221;;<br \/>\nisOK = false;<br \/>\n}<\/p>\n<p>if ( isOK == false ) {<br \/>\nwindow.alert(themessage);<br \/>\n} else {<br \/>\nfrmCreate.submit(frmCreate);<br \/>\n}<\/p>\n<p>}<\/p>\n<p>\/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n\/\/Checks if the entry is numeric<br \/>\nfunction isNumeric(inputVal) {<br \/>\nnumeric = true;<br \/>\ninputStr = inputVal.toString();<br \/>\nfor (var i = 0; i&lt; inputStr.length; i++) {<br \/>\nvar oneChar = inputStr.charAt(i);<\/p>\n<p>if (oneChar &lt; &#8220;0&#8221; || oneChar &gt; &#8220;9&#8221;) {<br \/>\nreturn false;<br \/>\n}<\/p>\n<p>}<\/p>\n<p>if (numeric == false) {<br \/>\nreturn false; }<br \/>\nelse {<br \/>\nreturn true; }<\/p>\n<p>}<\/p>\n<p>\/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nfunction LowerLimit_onblur(frmCreate) {<br \/>\nif ( !isNumeric( frmCreate.txtLowerLimit.value ) ) {<br \/>\nwindow.alert(&#8220;Enter a integer number&#8221;);<br \/>\nfrmCreate.txtLowerLimit.value = &#8220;&#8221;;<br \/>\nfrmCreate.txtLowerLimit.focus();<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/&#8211;&gt;<br \/>\n&lt;\/script&gt;<\/p>\n<p>&lt;\/head&gt;<br \/>\n&lt;body&gt;<\/p>\n<p>&lt;!&#8211; START OF MAIN FORM &#8211;&gt;<br \/>\n&lt;form name=&#8221;frmCreate&#8221; method=&#8221;post&#8221; action=&#8221;test.html&#8221;&gt;<\/p>\n<p>&lt;input type=&#8221;button&#8221; name=&#8221;Create&#8221; value=&#8221;Create&#8221; language=&#8221;javascript&#8221; onClick=&#8221;return button_onclick(frmCreate)&#8221; \/&gt;<\/p>\n<p>&lt;br\/&gt;&lt;br\/&gt;<br \/>\n&lt;table&gt;<br \/>\n&lt;tr&gt;<br \/>\n&lt;td&gt;<br \/>\n&lt;strong&gt;Product Item Reference&lt;\/strong&gt;<br \/>\n&lt;\/td&gt;<\/p>\n<p>&lt;td&gt;<br \/>\n&lt;input type=&#8221;text&#8221; name=&#8221;txtItem_Number&#8221; \/&gt;<br \/>\n&lt;\/td&gt;<br \/>\n&lt;tr&gt;<\/p>\n<p>&lt;tr&gt;<br \/>\n&lt;td&gt;<br \/>\n&lt;strong&gt;Product Item Name&lt;\/strong&gt;<br \/>\n&lt;\/td&gt;<\/p>\n<p>&lt;td&gt;<br \/>\n&lt;input type=&#8221;text&#8221; name=&#8221;txtItem_Name&#8221; size=&#8221;50&#8243; \/&gt;&lt;br\/&gt;<br \/>\n&lt;\/td&gt;<br \/>\n&lt;\/tr&gt;<\/p>\n<p>&lt;tr&gt;<br \/>\n&lt;td&gt;<br \/>\n&lt;strong&gt;Enter lower limit&lt;\/strong&gt;<br \/>\n&lt;\/td&gt;<br \/>\n&lt;td&gt;<br \/>\n&lt;input type=&#8221;text&#8221; name=&#8221;txtLowerLimit&#8221;\u00a0 value=&#8221;5&#8243; size=&#8221;3&#8243;\u00a0 LANGUAGE=&#8221;javascript&#8221; onBlur=&#8221;return LowerLimit_onblur(frmCreate)&#8221; \/&gt;<br \/>\n&lt;\/td&gt;<\/p>\n<p>&lt;\/table&gt;<br \/>\n&lt;\/form&gt;<br \/>\n&lt;!&#8211; END OF MAIN FORM &#8211;&gt;<\/p>\n<p>&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>The following HTML script illustrates a simple Javascript validation and submit script that checks inputs on the PC before it is submitted to the server.\u00a0 You might use this method on a web site before submission to the PHP script.\u00a0<span class=\"ellipsis\">&hellip;<\/span><\/p>\n<div class=\"read-more\"><a href=\"https:\/\/www.withinweb.com\/info\/a-simple-javascript-submit-and-validation-example\/\">Read more <span class=\"screen-reader-text\">A simple Javascript Submit and Validation example<\/span><span class=\"meta-nav\"> &#8250;<\/span><\/a><\/div>\n<p><!-- end of .read-more --><\/p>\n","protected":false},"author":40,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,14],"tags":[],"class_list":["post-883","post","type-post","status-publish","format-standard","hentry","category-general-php","category-site-design"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>A simple Javascript Submit and Validation example - PHP Web Applications<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.withinweb.com\/info\/a-simple-javascript-submit-and-validation-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A simple Javascript Submit and Validation example - PHP Web Applications\" \/>\n<meta property=\"og:description\" content=\"The following HTML script illustrates a simple Javascript validation and submit script that checks inputs on the PC before it is submitted to the server.\u00a0 You might use this method on a web site before submission to the PHP script.\u00a0&hellip;Read more A simple Javascript Submit and Validation example &#8250;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.withinweb.com\/info\/a-simple-javascript-submit-and-validation-example\/\" \/>\n<meta property=\"og:site_name\" content=\"PHP Web Applications\" \/>\n<meta property=\"article:published_time\" content=\"2012-09-17T10:17:01+00:00\" \/>\n<meta name=\"author\" content=\"paulv\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"paulv\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/a-simple-javascript-submit-and-validation-example\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/a-simple-javascript-submit-and-validation-example\\\/\"},\"author\":{\"name\":\"paulv\",\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/#\\\/schema\\\/person\\\/04da5531c302d55ffcd777fe81dbb93c\"},\"headline\":\"A simple Javascript Submit and Validation example\",\"datePublished\":\"2012-09-17T10:17:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/a-simple-javascript-submit-and-validation-example\\\/\"},\"wordCount\":459,\"commentCount\":0,\"articleSection\":[\"General PHP\",\"Site Design\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.withinweb.com\\\/info\\\/a-simple-javascript-submit-and-validation-example\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/a-simple-javascript-submit-and-validation-example\\\/\",\"url\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/a-simple-javascript-submit-and-validation-example\\\/\",\"name\":\"A simple Javascript Submit and Validation example - PHP Web Applications\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/#website\"},\"datePublished\":\"2012-09-17T10:17:01+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/#\\\/schema\\\/person\\\/04da5531c302d55ffcd777fe81dbb93c\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/a-simple-javascript-submit-and-validation-example\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.withinweb.com\\\/info\\\/a-simple-javascript-submit-and-validation-example\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/a-simple-javascript-submit-and-validation-example\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"A simple Javascript Submit and Validation example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/#website\",\"url\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/\",\"name\":\"PHP Web Applications\",\"description\":\"Information and support for products of WithinWeb.com\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/#\\\/schema\\\/person\\\/04da5531c302d55ffcd777fe81dbb93c\",\"name\":\"paulv\",\"url\":\"https:\\\/\\\/www.withinweb.com\\\/info\\\/author\\\/paulv\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"A simple Javascript Submit and Validation example - PHP Web Applications","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.withinweb.com\/info\/a-simple-javascript-submit-and-validation-example\/","og_locale":"en_US","og_type":"article","og_title":"A simple Javascript Submit and Validation example - PHP Web Applications","og_description":"The following HTML script illustrates a simple Javascript validation and submit script that checks inputs on the PC before it is submitted to the server.\u00a0 You might use this method on a web site before submission to the PHP script.\u00a0&hellip;Read more A simple Javascript Submit and Validation example &#8250;","og_url":"https:\/\/www.withinweb.com\/info\/a-simple-javascript-submit-and-validation-example\/","og_site_name":"PHP Web Applications","article_published_time":"2012-09-17T10:17:01+00:00","author":"paulv","twitter_card":"summary_large_image","twitter_misc":{"Written by":"paulv","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.withinweb.com\/info\/a-simple-javascript-submit-and-validation-example\/#article","isPartOf":{"@id":"https:\/\/www.withinweb.com\/info\/a-simple-javascript-submit-and-validation-example\/"},"author":{"name":"paulv","@id":"https:\/\/www.withinweb.com\/info\/#\/schema\/person\/04da5531c302d55ffcd777fe81dbb93c"},"headline":"A simple Javascript Submit and Validation example","datePublished":"2012-09-17T10:17:01+00:00","mainEntityOfPage":{"@id":"https:\/\/www.withinweb.com\/info\/a-simple-javascript-submit-and-validation-example\/"},"wordCount":459,"commentCount":0,"articleSection":["General PHP","Site Design"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.withinweb.com\/info\/a-simple-javascript-submit-and-validation-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.withinweb.com\/info\/a-simple-javascript-submit-and-validation-example\/","url":"https:\/\/www.withinweb.com\/info\/a-simple-javascript-submit-and-validation-example\/","name":"A simple Javascript Submit and Validation example - PHP Web Applications","isPartOf":{"@id":"https:\/\/www.withinweb.com\/info\/#website"},"datePublished":"2012-09-17T10:17:01+00:00","author":{"@id":"https:\/\/www.withinweb.com\/info\/#\/schema\/person\/04da5531c302d55ffcd777fe81dbb93c"},"breadcrumb":{"@id":"https:\/\/www.withinweb.com\/info\/a-simple-javascript-submit-and-validation-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.withinweb.com\/info\/a-simple-javascript-submit-and-validation-example\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.withinweb.com\/info\/a-simple-javascript-submit-and-validation-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.withinweb.com\/info\/"},{"@type":"ListItem","position":2,"name":"A simple Javascript Submit and Validation example"}]},{"@type":"WebSite","@id":"https:\/\/www.withinweb.com\/info\/#website","url":"https:\/\/www.withinweb.com\/info\/","name":"PHP Web Applications","description":"Information and support for products of WithinWeb.com","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.withinweb.com\/info\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.withinweb.com\/info\/#\/schema\/person\/04da5531c302d55ffcd777fe81dbb93c","name":"paulv","url":"https:\/\/www.withinweb.com\/info\/author\/paulv\/"}]}},"_links":{"self":[{"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/posts\/883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/users\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/comments?post=883"}],"version-history":[{"count":2,"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/posts\/883\/revisions"}],"predecessor-version":[{"id":885,"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/posts\/883\/revisions\/885"}],"wp:attachment":[{"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/media?parent=883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/categories?post=883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.withinweb.com\/info\/wp-json\/wp\/v2\/tags?post=883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}