<?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>Prozilla 2.0 &#187; Javascript</title>
	<atom:link href="http://prozilla.net/blog/category/website-tips-and-tricks/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://prozilla.net/blog</link>
	<description>Webmastery and SEO Community</description>
	<lastBuildDate>Sat, 12 Jun 2010 08:09:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Javascript Form Validation</title>
		<link>http://prozilla.net/blog/2010/02/03/javascript-form-validation/</link>
		<comments>http://prozilla.net/blog/2010/02/03/javascript-form-validation/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 18:21:45 +0000</pubDate>
		<dc:creator>Prozilla 2.0</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://prozilla.net/blog/?p=473</guid>
		<description><![CDATA[
			
				
			
		
Using forms
to collect data is required for specific information and formatting, which can be used for sending message, populating databases, calculations etc., however missing and improper field data can cause problems with generating information. This W3 tutorial shows how to use javascript to check
Required Fields



function validate_required(field,alerttxt)
{
with (field)
{
if (value==null&#124;&#124;value==&#8221;")
{
alert(alerttxt);return false;
}
else
{
return true;
}
}
}



The entire script, with the HTML [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fprozilla.net%2Fblog%2F2010%2F02%2F03%2Fjavascript-form-validation%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fprozilla.net%2Fblog%2F2010%2F02%2F03%2Fjavascript-form-validation%2F&amp;source=getprozilla&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Using forms<br />
to collect data is required for specific information and formatting, which can be used for sending message, populating databases, calculations etc., however missing and improper field data can cause problems with generating information. This W3 tutorial shows how to use javascript to check</p>
<h1>Required Fields</h1>
<table class="code" border="0" cellspacing="0" cellpadding="4" width="100%">
<tbody>
<tr>
<td bgcolor="#e9e9e9">function validate_required(field,alerttxt)</p>
<p>{</p>
<p>with (field)</p>
<p>{</p>
<p>if (value==null||value==&#8221;")</p>
<p>{</p>
<p>alert(alerttxt);return false;</p>
<p>}</p>
<p>else</p>
<p>{</p>
<p>return true;</p>
<p>}</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
<p>The entire script, with the HTML form could look something like this:</p>
<table class="code" border="0" cellspacing="0" cellpadding="4" width="100%">
<tbody>
<tr>
<td bgcolor="#e9e9e9">&lt;html&gt;</p>
<p>&lt;head&gt;</p>
<p>&lt;script type=&#8221;text/javascript&#8221;&gt;</p>
<p>function validate_required(field,alerttxt)</p>
<p>{</p>
<p>with (field)</p>
<p>{</p>
<p>if (value==null||value==&#8221;")</p>
<p>{</p>
<p>alert(alerttxt);return false;</p>
<p>}</p>
<p>else</p>
<p>{</p>
<p>return true;</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>function validate_form(thisform)</p>
<p>{</p>
<p>with (thisform)</p>
<p>{</p>
<p>if (validate_required(email,&#8221;Email must be filled out!&#8221;)==false)</p>
<p>{email.focus();return false;}</p>
<p>}</p>
<p>if (validate_required(name,&#8221;Name must be filled out!&#8221;)==false)</p>
<p>{email.focus();return false;}</p>
<p>}</p>
<p>}</p>
<p>&lt;/script&gt;</p>
<p>&lt;/head&gt;</p>
<p>&lt;body&gt;</p>
<p>&lt;form action=&#8221;submit.htm&#8221;<br />
onsubmit=&#8221;return validate_form(this)&#8221;<br />
method=&#8221;post&#8221;&gt;<br />
email: &lt;input type=&#8221;text&#8221; name=&#8221;email&#8221; size=&#8221;30&#8243;&gt;</p>
<p>name: &lt;input type=&#8221;text&#8221; name=&#8221;name&#8221; size=&#8221;30&#8243;&gt;<br />
&lt;input type=&#8221;submit&#8221; value=&#8221;Submit&#8221;&gt;</p>
<p>&lt;/form&gt;</p>
<p>&lt;/body&gt;</p>
<p>&lt;/html&gt;</td>
</tr>
</tbody>
</table>
<hr />
<h2>E-mail Validation</h2>
<p>The function below checks if the content has the general syntax of an email and looks for @ sign and a dot (.).<br />
Also, the @ must not be the first character of the email address, and the last<br />
dot must at least be one character after the @ sign:</p>
<table class="code" border="0" cellspacing="0" cellpadding="4" width="100%">
<tbody>
<tr>
<td bgcolor="#e9e9e9">function validate_email(field,alerttxt)</p>
<p>{</p>
<p>with (field)</p>
<p>{</p>
<p>apos=value.indexOf(&#8220;@&#8221;);</p>
<p>dotpos=value.lastIndexOf(&#8220;.&#8221;);</p>
<p>if (apos&lt;1||dotpos-apos&lt;2)</p>
<p>{alert(alerttxt);return false;}</p>
<p>else {return true;}</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
<p>The entire script, with the HTML form could look something like this:</p>
<table class="code" border="0" cellspacing="0" cellpadding="4" width="100%">
<tbody>
<tr>
<td bgcolor="#e9e9e9">&lt;html&gt;</p>
<p>&lt;head&gt;</p>
<p>&lt;script type=&#8221;text/javascript&#8221;&gt;</p>
<p>function validate_email(field,alerttxt)</p>
<p>{</p>
<p>with (field)</p>
<p>{</p>
<p>apos=value.indexOf(&#8220;@&#8221;);</p>
<p>dotpos=value.lastIndexOf(&#8220;.&#8221;);</p>
<p>if (apos&lt;1||dotpos-apos&lt;2)</p>
<p>{alert(alerttxt);return false;}</p>
<p>else {return true;}</p>
<p>}</p>
<p>}</p>
<p>function validate_form(thisform)</p>
<p>{</p>
<p>with (thisform)</p>
<p>{</p>
<p>if (validate_email(email,&#8221;Not a valid e-mail address!&#8221;)==false)</p>
<p>{email.focus();return false;}</p>
<p>}</p>
<p>}</p>
<p>&lt;/script&gt;</p>
<p>&lt;/head&gt;</p>
<p>&lt;body&gt;</p>
<p>&lt;form action=&#8221;submit.htm&#8221;<br />
onsubmit=&#8221;return validate_form(this);&#8221;<br />
method=&#8221;post&#8221;&gt;</p>
<p>Email: &lt;input type=&#8221;text&#8221; name=&#8221;email&#8221; size=&#8221;30&#8243;&gt;</p>
<p>&lt;input type=&#8221;submit&#8221; value=&#8221;Submit&#8221;&gt;</p>
<p>&lt;/form&gt;</p>
<p>&lt;/body&gt;</p>
<p>&lt;/html&gt;</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://prozilla.net/blog/2010/02/03/javascript-form-validation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
