<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The BHC Blog &#187; Web Design / SEO</title>
	<atom:link href="http://www.bhcblog.com/category/web-design-seo/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bhcblog.com</link>
	<description>The Technical Blog of Blackhawk Consulting</description>
	<lastBuildDate>Fri, 03 Sep 2010 19:39:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to validate a form using JavaScript</title>
		<link>http://www.bhcblog.com/2008/09/16/how-to-validate-a-form-using-javascript/</link>
		<comments>http://www.bhcblog.com/2008/09/16/how-to-validate-a-form-using-javascript/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 16:08:00 +0000</pubDate>
		<dc:creator>Jesse</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[IT Security]]></category>
		<category><![CDATA[Web Design / SEO]]></category>
		<category><![CDATA[Form]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://www.bhcblog.com/?p=58</guid>
		<description><![CDATA[Alot of companies have forms on their websites to help capture lead information and communicate effectively with customers and partners. Getting incomplete or invalid information can lessen the value of a potential lead so it is important to get complete and accurate information the first time. To validate a javascript form add a javascript function [...]]]></description>
			<content:encoded><![CDATA[<p>Alot of companies have forms on their websites to help capture lead information and communicate effectively with customers and partners.   Getting incomplete or invalid information can lessen the value of a potential lead so it is important to get complete and accurate information the first time.</p>
<p>To validate a javascript form add a javascript function that contains the validation information&#8230; Below is an example.</p>
<p>Add this section to the form html page between the header tags (adjust as necessary for your page):</p>
<blockquote><p>
&lt;script language=&#8221;JavaScript&#8221; type=&#8221;text/javascript&#8221;&gt;<br />
&lt;!&#8211; // function validate(form)<br />
{<br />
if(form.first.value == &#8220;&#8221;) {<br />
window.alert(&#8220;Please make sure the \&#8217; First Name \&#8217; field was properly completed.&#8221;);<br />
return false;<br />
}<br />
if(form.last.value == &#8220;&#8221;) {<br />
window.alert(&#8220;Please make sure the \&#8217; Last Name \&#8217; field was properly completed.&#8221;);<br />
return false;<br />
}<br />
if(form.phone.value.length &lt; 12) {<br />
window.alert(&#8220;Please make sure the \&#8217; Phone \&#8217; field is formated as: 703-555-5555.&#8221;);<br />
return false;<br />
}<br />
}
</p></blockquote>
<p>As you can see we are basically looking at a values entered and then comparing them to what we expect to find.</p>
<p>Now we must add the section of code that triggers our function to run.</p>
<p>In the top of the form add this:   onsubmit=&#8221;return checkform(this);</p>
<p>so your new line would be :</p>
<blockquote><p>
&lt;form method=&#8221;POST&#8221; action=&#8221;submit.asp&#8221; name=&#8221;form&#8221; onsubmit=&#8221;return validate(this);&#8221;&gt;
</p></blockquote>
<p>This will now call the javascript function when the user clicks the submit button. It will not launch the submit.asp page until the user has passed the validation test.</p>
<p>To test for not a value put an ! infront of the equation to be tested like the example below:</p>
<p>if(!(form.phone.value.length &lt; 12)) { &#8230;&#8230;</p>
<div class='bookmarkify'><a name='bookmarkify'></a><div class='title' title='Use these links to share this page with others'>_______________________________________<BR>PLEASE HELP BY BOOKMARKING OUR SITE...</div><div class='linkbuttons'><a href='http://del.icio.us/post?url=http://www.bhcblog.com/2008/09/16/how-to-validate-a-form-using-javascript/&amp;title=How to validate a form using JavaScript' title='Save to del.icio.us' onclick='target="_blank";' rel='nofollow'><img src='/wp-content/plugins/bookmarkify/delicious.ico' style='width:16px; height:16px; border:none;' alt='[del.icio.us]'  /></a> <a href='http://digg.com/submit?phase=2&amp;url=http://www.bhcblog.com/2008/09/16/how-to-validate-a-form-using-javascript/&amp;title=How to validate a form using JavaScript' title='Digg It!' onclick='target="_blank";' rel='nofollow'><img src='/wp-content/plugins/bookmarkify/digg.ico' style='width:16px; height:16px; border:none;' alt='[Digg]'  /></a> <a href='http://www.stumbleupon.com/submit?url=http://www.bhcblog.com/2008/09/16/how-to-validate-a-form-using-javascript/&amp;title=How to validate a form using JavaScript' title='Stumble It!' onclick='target="_blank";' rel='nofollow'><img src='/wp-content/plugins/bookmarkify/stumbleupon.ico' style='width:16px; height:16px; border:none;' alt='[StumbleUpon]'  /></a> </div></div>]]></content:encoded>
			<wfw:commentRss>http://www.bhcblog.com/2008/09/16/how-to-validate-a-form-using-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
