<?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>Haiders WebSpace &#187; JavaScript</title>
	<atom:link href="http://blog.creativeitp.com/category/posts-and-articles/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.creativeitp.com</link>
	<description>Let&#039;s talk about IT</description>
	<lastBuildDate>Sat, 27 Feb 2010 13:15:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Flipping an image vertically or horizontally using the Select tag (IE Only)</title>
		<link>http://blog.creativeitp.com/posts-and-articles/javascript/flipping-an-image-vertically-or-horizontally-using-the-select-tag-ie-only/</link>
		<comments>http://blog.creativeitp.com/posts-and-articles/javascript/flipping-an-image-vertically-or-horizontally-using-the-select-tag-ie-only/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 21:38:43 +0000</pubDate>
		<dc:creator>Haider al-Khateeb</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Internet Explorer]]></category>

		<guid isPermaLink="false">http://blog.creativeitp.com/?p=193</guid>
		<description><![CDATA[FlipV and FlipH filters can be used to flip images vertically or horizontally in IE (These filters works in IE only). the following code shows you how to control an image by using the HTML Select Tag to FlipV, FlipH or Apply both filters at the same time. 1 2 3 4 5 6 7 [...]]]></description>
			<content:encoded><![CDATA[<p><strong>FlipV</strong> and<strong> FlipH</strong> filters can be used to flip images vertically or horizontally in IE (<em>These filters works in IE only</em>). the following code shows you how to control an image by using the HTML Select Tag to FlipV, FlipH or Apply both filters at the same time. <span id="more-193"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span> 
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span> 
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>Applying FlipV and FlipH using the Select tag (IE Only)<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span> 
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">language</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;JavaScript&quot;</span>&gt;</span>
	function change()	
	{
var sel = document.getElementById(&quot;SelectFilter&quot;);
var SelectV = sel.options[sel.selectedIndex].value;
&nbsp;
if (SelectV == 'NoFilter')
{ document.getElementById(&quot;x&quot;).style.filter = '' }
&nbsp;
else if (SelectV == 'FlipVH')
{ document.getElementById(&quot;x&quot;).style.filter = 'Filter: flipV + Filter: flipH' }
&nbsp;
else
{ document.getElementById(&quot;x&quot;).style.filter = (SelectV == 'FlipH') ? 'FlipH' : 'FlipV'; }
	}
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span> 
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span> 
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;SelectFilter&quot;</span> <span style="color: #000066;">onChange</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;change()&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;NoFilter&quot;</span>&gt;</span>No Filter
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;FlipH&quot;</span>&gt;</span>Flip H
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;FlipV&quot;</span>&gt;</span>Flip V
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;FlipVH&quot;</span>&gt;</span>Both
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image-name.jpg&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;x&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span> 
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.creativeitp.com/posts-and-articles/javascript/flipping-an-image-vertically-or-horizontally-using-the-select-tag-ie-only/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript Injection (Form Editing)</title>
		<link>http://blog.creativeitp.com/posts-and-articles/javascript/javascript-injection-form-editing/</link>
		<comments>http://blog.creativeitp.com/posts-and-articles/javascript/javascript-injection-form-editing/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 20:40:52 +0000</pubDate>
		<dc:creator>Haider al-Khateeb</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Attack]]></category>
		<category><![CDATA[Forms]]></category>

		<guid isPermaLink="false">http://blog.creativeitp.com/?p=148</guid>
		<description><![CDATA[JavaScript codes can be injected in the address bars of web browsers to edit online forms before submitting them, bellow I am posting an example for archiving purposes. Assuming the page has a contact form, where submitted data is sent to an email address included in a hidden HTML input tag as in the following [...]]]></description>
			<content:encoded><![CDATA[<p>JavaScript codes can be injected in the address bars of web browsers to edit online forms before submitting them, bellow I am posting an example for archiving purposes.</p>
<p>Assuming the page has a contact form, where submitted data is sent to an email address included in a hidden HTML input tag as in the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">…
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ContactForm&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit.php&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Email&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;admin@website.com&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
…</pre></div></div>

<p>To change the email address to: <b>myemail@hotmail.com</b>, the following code can be injected:</p>
<p><span id="more-148"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">javascript<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">ContactForm</span>.<span style="color: #660066;">Email</span>.<span style="color: #660066;">value</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;myemail@hotmail.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Where <b>ContactForm</b> is the name of the form and <b>Email</b> is the name of the input tag.</p>
<p>To check that the value has actually been changed, view it with:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">javascript<span style="color: #339933;">:</span><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">ContactForm</span>.<span style="color: #000066;">Name</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If the form has no name, check the form order in the page, if it is the first, you may refer to it using: <b>forms[0]</b>. Same thing applies to the input tag, you may refer to it using: <b>elements[0]</b>.</p>
<p>This way, assuming the form is the first, and the order of the input tag in that form is 4, our codes will be:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">javascript<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">forms</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">elements</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">value</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;myemail@hotmail.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>and</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">javascript<span style="color: #339933;">:</span><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">forms</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">elements</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.creativeitp.com/posts-and-articles/javascript/javascript-injection-form-editing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Javascript Injection (Cookie Editing)</title>
		<link>http://blog.creativeitp.com/posts-and-articles/javascript/javascript-injection-cookie-editing/</link>
		<comments>http://blog.creativeitp.com/posts-and-articles/javascript/javascript-injection-cookie-editing/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 00:51:52 +0000</pubDate>
		<dc:creator>Haider al-Khateeb</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Attack]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[Firefox]]></category>

		<guid isPermaLink="false">http://blog.creativeitp.com/?p=138</guid>
		<description><![CDATA[Your browser’s address bar (URL bar) can be used to inject JavaScript code directly into the webpage you are visiting without reloading the page. The following codes are useful to do cookie editing: First, visit the targeted webpage and inject the following code to view realted cookie’s fields and the values assigned to them. javascript:alert&#40;document.cookie&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>Your browser’s address bar (URL bar) can be used to inject JavaScript code directly into the webpage you are visiting without reloading the page. The following codes are useful to do cookie editing:</p>
<p>First, visit the targeted webpage and inject the following code to view realted cookie’s fields and the values assigned to them.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">javascript<span style="color: #339933;">:</span><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">cookie</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Second, to edit a certain value use:<br />
<span id="more-138"></span><br />
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">javascript<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">cookie</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Field=myValue&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>For example, if the following field exist:</p>
<p><b>active=no</b></p>
<p>The value can be changed to <b>yes</b> with the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">javascript<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">cookie</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;active=yes&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If the field’s name does not exist, it will be created.<br />
To have more control over cookies, refer to a proper tutorial and inject the codes in a similar way.</p>
<p>In addition, there are cookies editors available online such as the following PlugIn for Mozilla FireFox:</p>
<p><b>Add N Edit Cookies</b><br />
Homepage: <a href="http://addneditcookies.mozdev.org" target="_blank">http://addneditcookies.mozdev.org</a>.<br />
Download latest release from: <a href="https://addons.mozilla.org/en-US/firefox/addon/573" target="_blank">https://addons.mozilla.org/en-US/firefox/addon/573</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.creativeitp.com/posts-and-articles/javascript/javascript-injection-cookie-editing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basic Form Validation</title>
		<link>http://blog.creativeitp.com/posts-and-articles/javascript/basic-form-validation/</link>
		<comments>http://blog.creativeitp.com/posts-and-articles/javascript/basic-form-validation/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 05:57:02 +0000</pubDate>
		<dc:creator>Haider al-Khateeb</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Forms]]></category>

		<guid isPermaLink="false">http://blog.creativeitp.com/?p=22</guid>
		<description><![CDATA[Who doesnt need to implement a data validation technique along with every online form? Bellow is a basic javascript code to check that no form is submitted with empty fields: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 [...]]]></description>
			<content:encoded><![CDATA[</p>
<p>Who doesnt need to implement a data validation technique along with every online form?</p>
<p>
Bellow is a basic javascript code to check that no form is submitted with empty fields:</p>
<p><span id="more-22"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script Language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;JavaScript&quot;</span><span style="color: #339933;">&gt;&lt;!--</span>
<span style="color: #003366; font-weight: bold;">function</span> Validator<span style="color: #009900;">&#40;</span>Form<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Form.<span style="color: #660066;">UserName</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Please enter a value for the <span style="color: #000099; font-weight: bold;">\&quot;</span>User Name<span style="color: #000099; font-weight: bold;">\&quot;</span> field.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Form.<span style="color: #660066;">UserName</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Form.<span style="color: #660066;">Password</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Please enter a value for the <span style="color: #000099; font-weight: bold;">\&quot;</span>Password<span style="color: #000099; font-weight: bold;">\&quot;</span> field.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Form.<span style="color: #660066;">Password</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>Form.<span style="color: #660066;">FullName</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Please enter a value for the <span style="color: #000099; font-weight: bold;">\&quot;</span>Full Name<span style="color: #000099; font-weight: bold;">\&quot;</span> field.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    Form.<span style="color: #660066;">FullName</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #006600; font-style: italic;">//--&gt;&lt;/script&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>center<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>form <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Signup&quot;</span> action <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;submit_form.php&quot;</span> method <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;post&quot;</span> 
onsubmit<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;return Validator(this)&quot;</span> <span style="color: #339933;">&gt;</span>
Username<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;</span>input type <span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text&quot;</span>  <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;UserName&quot;</span> size<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;20&quot;</span><span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>b<span style="color: #339933;">&gt;-&lt;/</span>b<span style="color: #339933;">&gt;</span> 
Password<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;</span>input type <span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text&quot;</span>  <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Password&quot;</span> size<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;20&quot;</span><span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>b<span style="color: #339933;">&gt;-&lt;/</span>b<span style="color: #339933;">&gt;</span> 
Fullname<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;</span>input type <span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text&quot;</span>  <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;FullName&quot;</span> size<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;20&quot;</span><span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;</span>b<span style="color: #339933;">&gt;-&lt;/</span>b<span style="color: #339933;">&gt;</span> 
<span style="color: #339933;">&lt;</span>input <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Submit&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Submit&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>center<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p"></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.creativeitp.com/posts-and-articles/javascript/basic-form-validation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Limit the number of ticks allowed for a list of check boxes</title>
		<link>http://blog.creativeitp.com/posts-and-articles/javascript/limit-the-number-of-ticks-allowed-for-a-list-of-check-boxes/</link>
		<comments>http://blog.creativeitp.com/posts-and-articles/javascript/limit-the-number-of-ticks-allowed-for-a-list-of-check-boxes/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 05:28:51 +0000</pubDate>
		<dc:creator>Haider al-Khateeb</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.creativeitp.com/?p=9</guid>
		<description><![CDATA[As part of an experiment for testing a new authentication mechanism for web applications (will post more about it sometime in the future) I needed my users to select only four images out of many while filling a form. I used a CheckBox beside every image and developed a JavaScript code to limit the number [...]]]></description>
			<content:encoded><![CDATA[</p>
<p>As part of an experiment for testing a new authentication mechanism for web applications (will post more about it sometime in the future) I needed my users to select only four images out of many while filling a form. </p>
<p>I used a CheckBox beside every image and developed a JavaScript code to limit the number of checkboxes allowed to be ticked.</p>
<p>
<span id="more-9"></span><br />
I am posting the code here followed by a Demo of how it works:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&nbsp;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">function</span> CheckBoxF<span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> total<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">do</span> <span style="color: #009900;">&#123;</span> 
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">SelPicForm</span>.<span style="color: #660066;">ChkBox</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">checked</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
total <span style="color: #339933;">=</span>total <span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>total <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Please select only four&quot;</span><span style="color: #009900;">&#41;</span>
document.<span style="color: #660066;">SelPicForm</span>.<span style="color: #660066;">ChkBox</span><span style="color: #009900;">&#91;</span>x<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">checked</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
i<span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&lt;</span> document.<span style="color: #660066;">SelPicForm</span>.<span style="color: #660066;">ChkBox</span>.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
&lt;/head&gt;
&nbsp;
&lt;body&gt;
&nbsp;
&lt;form name=&quot;SelPicForm&quot; method=&quot;post&quot; action=&quot;&quot;&gt;
&lt;table align=&quot;center&quot; cellspacing=&quot;15&quot;&gt;
&lt;tr&gt;
&lt;td colspan=&quot;3&quot; bgcolor=&quot;#c2c2c2&quot; align=&quot;middle&quot;&gt;
You may select &lt;b&gt;four&lt;/b&gt; pictures only!&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td  bgcolor=&quot;#f0f0f0&quot; align=&quot;middle&quot;&gt;(Picture 1)
&lt;input type=&quot;checkbox&quot; name=&quot;ChkBox&quot; value=&quot;1&quot; onclick=&quot;CheckBoxF(0)&quot;&gt;
&lt;/td&gt;
&lt;td  bgcolor=&quot;#f0f0f0&quot; align=&quot;middle&quot;&gt;(Picture 2)
&lt;input type=&quot;checkbox&quot; name=&quot;ChkBox&quot; value=&quot;2&quot; onclick=&quot;CheckBoxF(1)&quot;&gt;
&lt;/td&gt;
&lt;td  bgcolor=&quot;#f0f0f0&quot; align=&quot;middle&quot;&gt;(Picture 3)
&lt;input type=&quot;checkbox&quot; name=&quot;ChkBox&quot; value=&quot;3&quot; onclick=&quot;CheckBoxF(2)&quot;&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td  bgcolor=&quot;#f0f0f0&quot; align=&quot;middle&quot;&gt;(Picture 4)
&lt;input type=&quot;checkbox&quot; name=&quot;ChkBox&quot; value=&quot;4&quot; onclick=&quot;CheckBoxF(3)&quot;&gt;
&lt;/td&gt;
&lt;td  bgcolor=&quot;#f0f0f0&quot; align=&quot;middle&quot;&gt;(Picture 5)
&lt;input type=&quot;checkbox&quot; name=&quot;ChkBox&quot; value=&quot;5&quot; onclick=&quot;CheckBoxF(4)&quot;&gt;
&lt;/td&gt;
&lt;td  bgcolor=&quot;#f0f0f0&quot; align=&quot;middle&quot;&gt;(Picture 6)
&lt;input type=&quot;checkbox&quot; name=&quot;ChkBox&quot; value=&quot;6&quot; onclick=&quot;CheckBoxF(5)&quot;&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td  bgcolor=&quot;#f0f0f0&quot; align=&quot;middle&quot;&gt;(Picture 7)
&lt;input type=&quot;checkbox&quot; name=&quot;ChkBox&quot; value=&quot;7&quot; onclick=&quot;CheckBoxF(6)&quot;&gt;
&lt;/td&gt;
&lt;td  bgcolor=&quot;#f0f0f0&quot; align=&quot;middle&quot;&gt;(Picture 8)
&lt;input type=&quot;checkbox&quot; name=&quot;ChkBox&quot; value=&quot;8&quot; onclick=&quot;CheckBoxF(7)&quot;&gt;
&lt;/td&gt;
&lt;td  bgcolor=&quot;#f0f0f0&quot; align=&quot;middle&quot;&gt;(Picture 9)
&lt;input type=&quot;checkbox&quot; name=&quot;ChkBox&quot; value=&quot;9&quot; onclick=&quot;CheckBoxF(8)&quot;&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>Demo for the above code is as follows: </p>
<p><script type="text/javascript">
function CheckBoxF(x) {
var total=0;
var i=0;
do { 
if(document.SelPicForm.ChkBox[i].checked){
total =total +1;
}
if(total > 4){
alert("Please select only four")
document.SelPicForm.ChkBox[x].checked = false ;
return false;
}
i++;
}while(i < document.SelPicForm.ChkBox.length)
}
</script></p>
<form name="SelPicForm" method="post" action="">
<table align="center" cellspacing="15">
<tr>
<td colspan="3" bgcolor="#c2c2c2" align="middle">
You may select <b>four</b> pictures only!</td>
</tr>
<tr>
<td  bgcolor="#f0f0f0" align="middle">(Picture 1)</p>
<input type="checkbox" name="ChkBox" value="1" onclick="CheckBoxF(0)">
</td>
<td  bgcolor="#f0f0f0" align="middle">(Picture 2)</p>
<input type="checkbox" name="ChkBox" value="2" onclick="CheckBoxF(1)">
</td>
<td  bgcolor="#f0f0f0" align="middle">(Picture 3)</p>
<input type="checkbox" name="ChkBox" value="3" onclick="CheckBoxF(2)">
</td>
</tr>
<tr>
<td  bgcolor="#f0f0f0" align="middle">(Picture 4)</p>
<input type="checkbox" name="ChkBox" value="4" onclick="CheckBoxF(3)">
</td>
<td  bgcolor="#f0f0f0" align="middle">(Picture 5)</p>
<input type="checkbox" name="ChkBox" value="5" onclick="CheckBoxF(4)">
</td>
<td  bgcolor="#f0f0f0" align="middle">(Picture 6)</p>
<input type="checkbox" name="ChkBox" value="6" onclick="CheckBoxF(5)">
</td>
</tr>
<tr>
<td  bgcolor="#f0f0f0" align="middle">(Picture 7)</p>
<input type="checkbox" name="ChkBox" value="7" onclick="CheckBoxF(6)">
</td>
<td  bgcolor="#f0f0f0" align="middle">(Picture 8<span>)</span></p>
<input type="checkbox" name="ChkBox" value="8" onclick="CheckBoxF(7)">
</td>
<td  bgcolor="#f0f0f0" align="middle">(Picture 9)</p>
<input type="checkbox" name="ChkBox" value="9" onclick="CheckBoxF(8)">
</td>
</tr>
</table>
</form></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.creativeitp.com/posts-and-articles/javascript/limit-the-number-of-ticks-allowed-for-a-list-of-check-boxes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
