<?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>StanSight &#187; JavaScript</title>
	<atom:link href="http://stansight.com/WordPress/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://stansight.com/WordPress</link>
	<description>Coding for the Web - A JavaScript Resource</description>
	<lastBuildDate>Tue, 01 Dec 2009 13:31:10 +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>Simple Set and Get Cookie Scripts</title>
		<link>http://stansight.com/WordPress/2009/11/12/simple-set-and-get-cookie-scripts/</link>
		<comments>http://stansight.com/WordPress/2009/11/12/simple-set-and-get-cookie-scripts/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 12:52:50 +0000</pubDate>
		<dc:creator>Stan Slaughter</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[cookie]]></category>

		<guid isPermaLink="false">http://stansight.com/WordPress/?p=57</guid>
		<description><![CDATA[Since cookies are a common thing to use on the web I thought I would post the function which I use to set and read cookies ////////////////////////////////////////////////////////////////////////////// // setCookie // // Create a client side cookie. // // @param c_name - Name to call the cookie // @param value - Value to assign to the [...]]]></description>
			<content:encoded><![CDATA[<p>Since cookies are a common thing to use on the web I thought I would post the function which I use to set and read cookies <span id="more-57"></span></p>
<pre class="brush: jscript;">
//////////////////////////////////////////////////////////////////////////////
// setCookie
//
//		Create a client side cookie.
//
//  @param   c_name - Name to call the cookie
//  @param   value - Value to assign to the cookie
//  @param   expiredays - *optional* number of days before cookie expires
//////////////////////////////////////////////////////////////////////////////
function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ &quot;=&quot; +escape(value)+((expiredays==null) ? &quot;&quot; : &quot;;expires=&quot;+exdate.toGMTString());
}

//////////////////////////////////////////////////////////////////////////////
// getCookie
//
//		Get value of a client side cookie
//
//  @param   c_name - Cookie name.
//  @return  cookie value, or an empty string if cookie is not found
//////////////////////////////////////////////////////////////////////////////
function getCookie(c_name) {

	if (document.cookie.length&gt;0) {
		c_start=document.cookie.indexOf(c_name + &quot;=&quot;);
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(&quot;;&quot;,c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}

	return &quot;&quot;;
}
</pre>
<p>Here is an example of how you would use them</p>
<pre class="brush: jscript;">
// Set currentView cookie to &quot;View&quot; and set the value to expire in 30 days
setCookie(&quot;currentView&quot;,&quot;View&quot;,30);
.
.
.
// Get current view mode from cookie
var myCurrentView = getCookie(&quot;currentView&quot;);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://stansight.com/WordPress/2009/11/12/simple-set-and-get-cookie-scripts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Get Submitted Form Values</title>
		<link>http://stansight.com/WordPress/2009/02/11/get-submitted-form-values/</link>
		<comments>http://stansight.com/WordPress/2009/02/11/get-submitted-form-values/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 20:15:22 +0000</pubDate>
		<dc:creator>Stan Slaughter</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[fields]]></category>
		<category><![CDATA[form]]></category>

		<guid isPermaLink="false">http://stansight.com/WordPress/2009/02/11/get-submitted-form-values/</guid>
		<description><![CDATA[Getting the values from a form which has been submitted is easy if you are using a server side language such as PHP, JSP, or ASP. But – sometimes you can’t use a server side language (restrictions of your ISP, you need to create a CD based demo or prototype, etc..), and this is where [...]]]></description>
			<content:encoded><![CDATA[<p>Getting the values from a form which has been submitted is easy if you are using a server side language such as PHP, JSP, or ASP.  </p>
<p>But – sometimes you can’t use a server side language (restrictions of your ISP, you need to create a CD based demo or prototype, etc..), and this is where JavaScript can step in and save the day.<span id="more-51"></span></p>
<h2>The right form method</h2>
<p>If your form has uses the “post” method (&lt;form method=”post”&gt;) then you are out of luck.  The form field values are essentially hidden from the client side  – but if your form uses the “get” method (&lt;form method=”get”&gt;) then you are in luck, because when the form posts to the target page all the field names and values are stuck on as part of the URL.</p>
<p>Using this knowledge and the fact that “window.location.href” will return the value of the URL address bar, allows you to use JavaScript retrieve the form field the values that you need.</p>
<h2>The Functions</h2>
<p>OK, the address bar can look like a mess after a form submit.  But if you look at it closely you’ll see that the names of your form fields and the values that they have been assigned are part of that mess.  </p>
<p>I’ve written some functions which you can use to painlessly pick out the values of the fields your are interested in and then display them on the screen (or assign their values to other HTML objects, such as hidden input fields or DIV’s) </p>
<p>Take the functions below and include them between the HEAD tags of the target page.</p>
<h3>Get values</h3>
<p>If you need to just retrieve the value so you can use it in your own JavaScript functions then just use the getParameter function.</p>
<p><strong>Example:</strong></p>
<pre class="brush: xml;">&lt;script&gt;
	if (getParameter(&quot;loginName&quot;) == &quot;&quot;) {
		alert(&quot;You must supply a login name&quot;);
	}
&lt;/script&gt;
</pre>
<p><strong>Code:</strong></p>
<pre class="brush: jscript;">
//////////////////////////////////////////////////////////////////////////////
// getParameter
//
//		If page was called as an action from a form post (method=&quot;get&quot;) then
//		get the value of the parameter &quot;paramName&quot; from the name/value pairs
//		in the current URL
//
//  @param   paramName	- name of parameter to retreive value of
//  @return  results[1]	- value of parameter extracted from location.href
//////////////////////////////////////////////////////////////////////////////
function getParameter(paramName) {

	// Build regex expression to find paramName in window.location.href
	// and then parse out everything after the &quot;=&quot; sign and before the &quot;&amp;&quot;
	// sign
	paramName = paramName.replace(/[\[]/,&quot;\\\[&quot;).replace(/[\]]/,&quot;\\\]&quot;);
	var regexS = &quot;[\\?&amp;]&quot;+paramName+&quot;=([^&amp;#]*)&quot;;
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );

	if( results == null )
		return &quot;&quot;;
	else {
		returnValue = unescape(results[1]);				// Unescape it
		returnValue = returnValue.replace(/\+/g, ' ');	// Replace plus sign with space
		return returnValue;
	}
}
</pre>
<h3>Assign values</h3>
<p>If you wish to take the field value and assign it to some other element on your page (like a hidden field) then you can use the copyParameter function to copy the value of the field to any other element on your page who has an ID that is the same as the fields name.</p>
<p><strong>Example:</strong></p>
<pre class="brush: xml;">
	&lt;input type=&quot;hidden&quot; id=&quot;loginName&quot; name=&quot;loginName&quot;&gt;
	&lt;script&gt;copyParameterValue(&quot;loginName&quot;);&lt;/script&gt;
</pre>
<p><strong>Code:</strong></p>
<pre class="brush: jscript;">
//////////////////////////////////////////////////////////////////////////////
// copyParameter
//
//		Take the results of the getParameter function and assing it to the
//		value of an element on the page whoose ID matches the parameters name
//
//  @param   paramName	- name of parameter to retreive value of *AND* ID
//						  of element on page
//  @return  void
//////////////////////////////////////////////////////////////////////////////
function copyParameterValue(paramName) {
	var paramValue = getParameter(paramName);
	if (document.getElementById(paramName) != null) {
		document.getElementById(paramName).value = paramValue;
	}
}
</pre>
<h3>Show values</h3>
<p>If you just wish to display the value of a field on the page then just use the showParameter function where ever you want the value displayed</p>
<p><strong>Example:</strong></p>
<pre class="brush: xml;">
&lt;td&gt;Login Name: &lt;script&gt;showParameter(&quot;loginName&quot;)&lt;/script&gt;&lt;/td&gt;
</pre>
<p><strong>Code:</strong></p>
<pre class="brush: jscript;">
//////////////////////////////////////////////////////////////////////////////
// showParameter
//
//		Display the results of the getParameter function at the current
//		location in the document body.
//
//  @param   paramName	- name of parameter to retreive value of
//  @return  paramValue	- value of paramter written to the document.
//////////////////////////////////////////////////////////////////////////////
function showParameter(paramName) {
	// If object exists on page with the same ID as the param name then
	// copy set its value to the parameter value
	copyParameterValue(paramName);

	var paramValue = getParameter(paramName);	// Get parameter value
	document.write(paramValue);					// Write to document
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://stansight.com/WordPress/2009/02/11/get-submitted-form-values/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easy to use Tab Navigation</title>
		<link>http://stansight.com/WordPress/2009/02/10/easy-to-use-tab-navigation/</link>
		<comments>http://stansight.com/WordPress/2009/02/10/easy-to-use-tab-navigation/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 17:26:48 +0000</pubDate>
		<dc:creator>Stan Slaughter</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Navigation]]></category>
		<category><![CDATA[Tab]]></category>

		<guid isPermaLink="false">http://stansight.com/WordPress/2009/02/10/easy-to-use-tab-navigation/</guid>
		<description><![CDATA[Tab Navigation can give a very professional look to your web page. Example The problem with most of the Tab Navigation solutions available is how messy it tends to make your HTML code. This has lead many people to not even attempt to use them. Scared off by the amount of JavaScript and CSS code [...]]]></description>
			<content:encoded><![CDATA[<p>Tab Navigation can give a very professional look to your web page.</p>
<p><img src="http://www.stansight.com/tab/tab.gif" alt="tab" /><br />
<a href="http://www.stansight.com/tab/tab1.html">Example</a></p>
<p>The problem with most of the Tab Navigation solutions available is how messy it tends to make your HTML code.    This has lead many people to not even attempt to use them.  Scared off by the amount of JavaScript and CSS code required to make them work.<span id="more-50"></span></p>
<p>It was this which lead me to come up with a solution that would be easy to implement and require little to no JavaScript knowledge to use.  </p>
<p>I’ve created a <a href="http://www.stansight.com/tab/tab.css">CSS file</a> and a <a href="http://www.stansight.com/tab/tab.js">JavaScript file</a> for you to use.  All you need do is to include these files in your page by placing the following two lines in between your HEAD tags</p>
<pre class="brush: xml;">
&lt;script src=&quot;tab.js&quot;&gt;&lt;/script&gt;
&lt;link href=&quot;tab.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;
</pre>
<p>Now, where ever you wish the tab navigation page to display in your page use the HTML UL/LI element like below.</p>
<pre class="brush: xml;">
&lt;ul class=&quot;TabContainer&quot;&gt;
	&lt;li&gt;Tab 0&lt;/li&gt;
	&lt;li&gt;Tab 1&lt;/li&gt;
	&lt;li&gt;Tab 2&lt;/li&gt;
	&lt;li&gt;Tab 3&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>As long as the UL tag has the class of “TabContainer” assigned to it, each LI element will become a tab.</p>
<p>For the content you wish to display when the tab is clicked, create a div to hold the content and assign it the class name of “TabContent”</p>
<pre class="brush: xml;">
&lt;div class=&quot;TabContent&quot;&gt;
	&lt;p&gt;I am the content for Tab 0&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;TabContent&quot;&gt;
	&lt;p&gt;I am the content for Tab 1&lt;/p&gt;
&lt;/div&gt;
.
.
.
&lt;div class=&quot;TabContent&quot;&gt;
	&lt;p&gt;I am the content for Tab 3&lt;/p&gt;
&lt;/div&gt;
</pre>
<p>That’s it.  You are done (as long you have at least the same number of “TabContent“ divs as you have tabs) .  Clicking on Tab 0 will display what is inside the first div, clicking on Tab 1 will display what is inside the second div, etc.. </p>
<p><a href="http://www.stansight.com/tab/tab1.html">Click to see Example 1</a></p>
<p>If you wish to use a different color for your tabs simply edit the class “TabColor” in the tab.css file to change it to the color you want.</p>
<h2>Tab Sub Menu</h2>
<p>If you have the need for a top level navigation menu to appear within each tab then inside each of the content divs place your list of hyper links inside a div with a class of “TabTopNavContent”</p>
<pre class="brush: xml;">
&lt;div class=&quot;TabContent&quot;&gt;
	&lt;div class=&quot;TabTopNavContent&quot;&gt;
		&lt;a href=&quot;#&quot;&gt;Link 1&lt;/a&gt;
		&lt;a href=&quot;#&quot;&gt;Link 2&lt;/a&gt;
		&lt;a href=&quot;#&quot;&gt;Link 3&lt;/a&gt;
		&lt;a href=&quot;#&quot;&gt;Link 4&lt;/a&gt;
		&lt;a href=&quot;#&quot;&gt;Link 5&lt;/a&gt;
	&lt;/div&gt;

	&lt;p&gt;I am the content for Tab 0&lt;/p&gt;
&lt;/div&gt;
</pre>
<p><a href="http://www.stansight.com/tab/tab2.html">Click to see Example 2</a></p>
<h2>Source Code</h2>
<h3>tab.js</h3>
<pre class="brush: jscript;">function showTab (tabNum) {

	// Build Tab and Content ID's based on the tab number
	var tabID = 'Tab' + tabNum;
	var contentID = 'Content' + tabNum;

	// Get the LI object based on the tabID
	objLI = document.getElementById(tabID);

	// If the object exists
	if (objLI) {
		// Get the LI Objects parent (which should be the UL element the LI tag is in)
		objUL = objLI.parentNode;

		// Get all LI's in the UL and set their class and color
		var LIs = objUL.getElementsByTagName(&quot;li&quot;);
		for (var i = 0; i &lt; LIs.length; i++) {
			var classString = 'Tab TabColor';
			LIs[i].className = classString;
		}

		// Show wanted tab is seleted
		objLI.className += ' Selected';

		// *****
		// ***** Step 2 - Show Tab Content
		// *****

		// Scan for all DIV objects on page that contain the classname TabContent and hide them
		var divObj = document.getElementsByTagName('div');
		for (var i = 0; i &lt; divObj.length; i++) {
			if (divObj[i].className.indexOf(&quot;TabContent&quot;) &gt;= 0) divObj[i].style.display='none';
		}

		// Show wanted content DIV
		contentObj = document.getElementById(contentID);
		if ( typeof contentObj != &quot;undefined&quot; &amp;&amp; contentObj != null ) contentObj.style.display='';
	}

}

function BuildTabs() {

	// Scan for all UL objects on page that contain the classname TabContainer
	var ulObj = document.getElementsByTagName('ul');

	for (var i = 0; i &lt; ulObj.length; i++) {
		if (ulObj[i].className.indexOf(&quot;TabContainer&quot;) &gt;= 0) {

			// Get all LI's in the UL and set their class name to &quot;Tab&quot;
			var LIs = ulObj[i].getElementsByTagName(&quot;li&quot;);
			for (var j = 0; j &lt; LIs.length; j++) {

				// Assign Tab Class and Color
				var classString = 'Tab TabColor';
				if (j==0) classString +=  ' Selected';
				LIs[j].id = &quot;Tab&quot; + j;
				LIs[j].className = classString;
				LIs[j].innerHTML = &quot;&lt;a href=\&quot;#&quot; + j + &quot;\&quot; onClick=\&quot;showTab('&quot; + j + &quot;');\&quot;&gt;&quot; +
									LIs[j].innerHTML +
									&quot;&lt;/a&gt;&quot;;
			}
		}
	}

	// Scan for all DIV objects on page that contain the classname TabContent
	var divObj = document.getElementsByTagName('div');
	var cnt = 0;
	for (var i = 0; i &lt; divObj.length; i++) {

		if (divObj[i].className.indexOf(&quot;TabContent&quot;) &gt;= 0) {

			// Hide it
			divObj[i].style.display='none';
			divObj[i].id = &quot;Content&quot; + cnt;

			// Create colored line and insert it as first item in content div
			lineDiv = document.createElement(&quot;div&quot;);
			lineDiv.className = &quot;TabTopLine TabColor&quot;;
			divObj[i].insertBefore(lineDiv, divObj[i].firstChild); 

			// See if TabContent Div contains a top level navigation div
			var topNavFound = false;
			var tabNavObj = divObj[i].getElementsByTagName('div');
			for (var j = 0; j &lt; tabNavObj.length; j++) {
				// If top leven navigation div found then change background color to match tab
				if (tabNavObj[j].className.indexOf(&quot;TabTopNavContent&quot;) &gt;= 0) {
					tabNavObj[j].className += &quot; TabColor&quot;;
					topNavFound = true;
				}
			}

			// Display first one
			cnt+= 1;
			if (cnt == 1) divObj[i].style.display='';

		}
	}

	// If URL has a hash value then assume it contains the ID of the tab you wish to display
	// so call the showTab function
	locationHash = window.location.hash;
	if (locationHash.length &gt; 0) showTab(locationHash.substring(1));
}

window.onload = BuildTabs;
</pre>
<h3>tab.css</h3>
<pre class="brush: css;">.PageContainer {
	width:640px;
}

.TabContainer {
	border-bottom:1px solid #9f9f9f;
	clear:both;
	display:block;
	height:24px;
	list-style-type: none;
	margin:0;
	padding:0 0 0 10px;
}

.Tab {
	border-left:1px solid #9f9f9f;
	border-top:1px solid #9f9f9f;
	border-right:1px solid #9f9f9f;
	float:left;
	font-family:Arial, Helvetica, sans-serif;
	font-size:13px;
	height: 15px;
	margin-right:2px;
	opacity: .6;
	filter: alpha(opacity=60);
	padding:4px 10px;
}

.Tab:hover {
	opacity: 1;
	filter: alpha(opacity=100);
}

.Tab a {
	color:#5F5F5F;
	text-decoration:none;
}

.TabContent {
	background:#FFFFFF;
	border-left:1px solid #9f9f9f;
	border-right:1px solid #9f9f9f;
	border-bottom:1px solid #9f9f9f;
	font-family:Arial, Helvetica, sans-serif;
	font-size:11px;
}

.TabContent p {
	margin:0px;
	padding:8px;
}

.TabTopLine {
	display:block;
	height:3px;
	line-height:3px;
}

.TabTopNavContent {
	display:block;
	font-family:Arial, Helvetica, sans-serif;
	font-size:11px;
	height:20px;
}

.TabTopNavContent a {
	color:#000000;
	font-family:Arial, Helvetica, sans-serif;
	font-size:11px;
	font-weight:bold;
	margin-left:8px;
}

.Selected {
	border-left:1px solid #9f9f9f;
	border-top:1px solid #9f9f9f;
	border-right:1px solid #9f9f9f;
	filter: alpha(opacity=100);
	opacity: 1;
	padding:5px 10px 4px 10px;
}

.Selected a {
	border:0;
	color:#000000;
	font-weight:bold;
	text-decoration:none;
}

/* This is the background colors for the tabs */
.TabColor {background:#FEDA00;}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://stansight.com/WordPress/2009/02/10/easy-to-use-tab-navigation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Broken Image Icon Replacement</title>
		<link>http://stansight.com/WordPress/2009/02/03/broken-image-icon-replacement/</link>
		<comments>http://stansight.com/WordPress/2009/02/03/broken-image-icon-replacement/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 22:34:54 +0000</pubDate>
		<dc:creator>Stan Slaughter</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[broken image]]></category>
		<category><![CDATA[broken link]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[image replacement]]></category>
		<category><![CDATA[missing image]]></category>

		<guid isPermaLink="false">http://stansight.com/WordPress/2009/02/03/broken-image-icon-replacement/</guid>
		<description><![CDATA[Ever create a web page to hold images that someone else provides ? What happens when they remove the image, yet not the code from the page ? Well, you get that big red &#8220;X&#8221; missing image icon in place of the nice image that used to be there. It can make a nicely laid [...]]]></description>
			<content:encoded><![CDATA[<p>Ever create a web page to hold images that someone else provides ?  What happens when they remove the image, yet not the code from the page ?</p>
<p>Well, you get that big red &#8220;X&#8221; missing image icon in place of the nice image that used to be there.  It can make a nicely laid out page look really bad. <img src='http://stansight.com/WordPress/wp-content/uploads/2009/02/redx.gif' align="top" alt='redX' /> <img src='http://stansight.com/WordPress/wp-content/uploads/2009/02/redx.gif' align="top" alt='redX' /> <img src='http://stansight.com/WordPress/wp-content/uploads/2009/02/redx.gif' align="top" alt='redX' /> </p>
<p>What I&#8217;ve done is to create a couple of JavaScript functions that you can just place in the top of the page and forget about.  Everytime the page loads it will look for those missing/broken images and replace the horrible red &#8220;X&#8221; with any image you want to take its place.</p>
<p>Or &#8211; you can just hide it and make the red &#8220;X&#8221; disappear.<span id="more-44"></span></p>
<p><strong>Example: </strong><a href='http://www.stansight.com/BrokenImageCheck.html'> BrokenImageCheck.html</a><br />
<strong>Source Code:</strong></p>
<pre class="brush: jscript;">
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;&gt;
&lt;title&gt;Broken Link Replacement&lt;/title&gt;
&lt;script&gt;
	function ImageOk(img) {
		// Body has finished loading so if img is not complete then
		// you  have a broken image so return false - image is not ok
		if (!img.complete) return false;

		// if naturalWidth is undefined or zero then the image failed to load
		// so return false - image is not ok
		if (typeof img.naturalWidth != &quot;undefined&quot; &amp;&amp; img.naturalWidth == 0) return false;

		// Passed all checks - image succeeded in loading - image is ok
		return true;
	}

	function BrokenImageCheck() {
		// Name of image to replace broken image icon with
		var replacementImg = &quot;/images/NoPhotoOnFile.gif&quot;;

		// Loop through all images in the document
		for (var i = 0; i &lt; document.images.length; i++) {
			// If image did not finish loading
			if (!ImageOk(document.images[i])) {
				document.images[i].src = replacementImg;
				// document.images[i].style.display = &quot;none&quot;;
			}
		}
	}

	// After body loads check all images to see if the sucessfully loaded
	window.onload=BrokenImageCheck;
&lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;
	Broken Link &lt;img src=&quot;IdoNotExist.gif&quot;&gt;&lt;br&gt;
	&lt;br&gt;
	The above link should appear with a replacement image in place of the broken image icon&lt;br&gt;
&lt;/body&gt;

&lt;/html&gt;
</pre>
<p>In the above example the file &#8220;IdoNotExist.gif&#8221; does not exist and would normally case the broken image icon (red &#8220;X&#8221;) to appear in it&#8217;s place.</p>
<p>What happens is that in line 35 the assignment</p>
<pre class="brush: jscript;">
window.onload=BrokenImageCheck;
</pre>
<p>Causes the JavaScript function &#8220;BrokenImageCheck&#8221; to run after the web page finishes loading.  BrokenImageCheck will then scan through all of the images on the web page, calling the function &#8220;ImageOk&#8221; to see if any had troubles loading.  If it determines that the image did not completely load then the assignment on line 28</p>
<pre class="brush: jscript;">
				document.images[i].src = replacementImg;
				// document.images[i].style.display = &quot;none&quot;;
</pre>
<p>will replace it with any image you wish to use in its place.</p>
<p>If you only want to just suppress the broken image icon from appearing then comment out the .src= assignment and uncomment the display=&#8221;none&#8221; assignment in the BrokenImageCheck function</p>
]]></content:encoded>
			<wfw:commentRss>http://stansight.com/WordPress/2009/02/03/broken-image-icon-replacement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Floating Table Titles</title>
		<link>http://stansight.com/WordPress/2008/07/29/floating-table-titles/</link>
		<comments>http://stansight.com/WordPress/2008/07/29/floating-table-titles/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 22:15:30 +0000</pubDate>
		<dc:creator>Stan Slaughter</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[fixed]]></category>
		<category><![CDATA[float]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[Table]]></category>

		<guid isPermaLink="false">http://stansight.com/WordPress/2008/07/29/floating-table-titles/</guid>
		<description><![CDATA[Table Titles Float to stay in view Tested to work in Firefox 3, Internet Explorer 7, Chrome, and Safari 3.1 You will never loose sight of a tables column titles as long as the table is visible on the screen ! Click to see Example Invisibly in the background this script will take your tables [...]]]></description>
			<content:encoded><![CDATA[<p></p>
<h3>Table Titles Float to stay in view<br />
<span style="font-size:10px">Tested to work in Firefox 3, Internet Explorer 7, Chrome, and Safari 3.1</span><br />
</h3>
<p>You will never loose sight of a tables column titles as long as the table is visible on the screen !</p>
<p>Click to see <a href="http://www.stansight.com/TableFloaterTitle.html">Example</a></p>
<p>Invisibly in the background this script will take your tables exsting titles and &#8220;fix&#8221; them so as you scroll down the page they will always remain in view.</p>
<p>To use the script just include the <a href="http://www.stansight.com/TableFloaterTitle.js">TableFloaterTitle.js</a> file in the head of your document.</p>
<pre class="brush: jscript;">
&lt;script src=”TableFloaterTitle.js”&gt;&lt;/script&gt;
</pre>
<p><span id="more-28"></span><br />
To make the tables whoose titles you want to float just give the table a class of &#8220;FloatTitle&#8221;</p>
<pre class="brush: xml;">
&lt;table class=&quot;FloatTitle&quot;&gt;
  &lt;thead&gt;
    &lt;tr bgcolor=&quot;#FFCC33;&quot;&gt;&lt;td&gt;Title #1&lt;/td&gt;...&lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;&lt;td&gt;Stuff&lt;/td&gt;.../tr&gt;
    &lt;tr&gt;&lt;td&gt;Stuff&lt;/td&gt;...&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;Stuff&lt;/td&gt;...&lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
</pre>
<p>Currently tested to work in Firefox 3, IE 7, and Safari 3.1.2</p>
<p>Note: For now the table titles must be inside a THEAD tag</p>
<p>Another approach to making a tables headings and titles remain in view can be found here:</p>
<p>http://stansight.com/WordPress/2008/07/03/fixed-table-head/</p>
<h3>The Code &#8211; <a href="http://www.stansight.com/TableFloaterTitle.js">TableFloaterTitle.js</a> </h3>
<pre class="brush: jscript;">// *****************************************************************************
// ** TableFloaterTitle.js
// **
// ** Unobtrusive JavaScript function which will keep the titles of a table on
// ** screen as the user scrolls down.  The titles will 'float' keeping in view
// ** as long as any part of the table remains in view.
// **
// ** Author: Stan Slaughter
// ** Web: http://www.StanSight.Com/
// *****************************************************************************

  //////////////////////////////////////////////////////////////////////////////
  // startFloatTitle - Start tables floating
  //
  //  This function will scan the page looking for every &quot;table&quot; on it.
  //  Any table which has a class of &quot;FloatTitle&quot; will have its ID value
  //  passed on to the function for the actual float process
  //////////////////////////////////////////////////////////////////////////////

  function startFloatTitle() {

    var cnt=0;
    var allTableIDs = new Array();
    allTables = document.getElementsByTagName(&quot;table&quot;);

    // Scan page for all tables with a class of &quot;FloatTitle&quot;
    for (i=0;i&lt;allTables.length; i++) {
      if (allTables[i].className == &quot;FloatTitle&quot;) {

        // Get the ID. If no ID exists then assign one
        tableID = allTables[i].id;
        if ( tableID == &quot;&quot;) {
          tableID = &quot;tmpFloatTitleTableId&quot; + cnt;
          allTables[i].id = tableID;
        } 

        // Save ID's
        allTableIDs[cnt] = tableID;
        cnt++;
      }
    }

    // Start floating the tables title
    for (i=0;i&lt;allTableIDs.length; i++) {
      floatTitle(allTableIDs[i],i);
    }
  }

  //////////////////////////////////////////////////////////////////////////////
  // floatTitle - Start the float process
  //  @param tableID - ID of table that floating title will be created for
  //  @param cnt - Number representing table - for tracking seperate float events
  //
  //  This function calls the functions which create the floating title and
  //  start the floating process
  //////////////////////////////////////////////////////////////////////////////

  var floatTitleTimer = new Array();
  function floatTitle(tableID,cnt) {

    // Stop any old Loops
    if (typeof(floatTitleTimer[cnt])== 'undefined') floatTitleTimer[cnt] = 0;
    clearTimeout(floatTitleTimer[cnt]);

    // Create title object then start float loop
    titleID = createTitleObj(tableID);
    floatTitleLoop(tableID,titleID,cnt);

  }

  //////////////////////////////////////////////////////////////////////////////
  // createTitleObj - Create the floating object for this table
  //  @param tableID - ID of table that floating title will be created for
  //  @return titleWrapperID - ID of div which contains a copy of tables THEAD
  //
  //  Clone the THEAD from the table, create a new table to place it in then
  //  create a DIV wrapper to place it in. The ID for the DIV is returned to
  //  the calling function so it can be used to position the object in the
  //  floating function.
  //////////////////////////////////////////////////////////////////////////////

  function createTitleObj (tableID) {

    var titleWrapperID = tableID + &quot;Title&quot;;
    var titleTableID = tableID + &quot;TitleTable&quot;;

    // If Title has not been created yet
    if (document.getElementById(titleWrapperID)==null) {

      // &quot;clone&quot; the Table's thead
      tableObj = document.getElementById(tableID);
      clonedtHead=tableObj.tHead.cloneNode(true);

      // Create wrapper div
      titleWrapperObj = document.createElement(&quot;div&quot;);
      titleWrapperObj.setAttribute(&quot;id&quot;, titleWrapperID);

      // Create the Title table
      TitleTable = document.createElement(&quot;table&quot;);
      TitleTable.setAttribute(&quot;id&quot;, titleTableID);

      // Append Cloned thead to the Title table
      TitleTable.appendChild( clonedtHead );

      // Append table to div container
      titleWrapperObj.appendChild(TitleTable);

      // Insert wrapper div into the DOM before Table
      parentDiv = tableObj.parentNode;
      parentDiv.insertBefore(titleWrapperObj, tableObj);

      // Initially position container
      titleWrapperObj.style.position=&quot;absolute&quot;;
      titleWrapperObj.style.top = &quot;0px&quot;;
      titleWrapperObj.style.zIndex=&quot;1&quot;;
    }

    tableObj = document.getElementById(tableID);
    titleTableObj = document.getElementById(titleTableID);

    // Set Title width to be the same as Table
    titleWrapperObj = document.getElementById(titleWrapperID);
    titleWrapperObj.style.width = tableObj.offsetWidth + 'px';

    // Set widths of Title TD's to same as Table TD's
    tableCells = tableObj.tHead.rows[0].cells;
    titleTableCells = titleTableObj.tHead.rows[0].cells;

    for (var i=0; i != tableCells.length; i++) {
      titleTableCells[i].style.width = (tableCells[i].clientWidth)+ 'px';
      titleTableCells[i].style.cursor = 'normal';
    }

    return titleWrapperID;
  }

  //////////////////////////////////////////////////////////////////////////////
  // floatTitleLoop - Float the titles up and down the table as the page scrolls
  //  @param tableID - ID of table that wants floating title
  //  @param titleID - ID of div that will float (contains copy of tableID's THEAD)
  //  @param cnt - Number representing table - for tracking seperate float events
  //
  //  Keep the title object in view as the table postion changes as a user
  //  scrolls up and down in the window
  //////////////////////////////////////////////////////////////////////////////

  function floatTitleLoop(tableID,titleID,cnt) {

    // If Table and Title objects exist
    if (document.getElementById(tableID) !=null &amp;&amp; document.getElementById(titleID) !=null) {

      // Set value to be number of pixels from screen top that you wish
      // scrolling to start at. 0=top, 10=10 pixels down from top, etc..
      // Useful for those who happen to have top screen banners
      var	startOffsetTop = 0;

      // Get start and stop float positions from table
      var tableObj = document.getElementById(tableID);
      var tablePos = FindPosition(tableObj);
      var startTop = tablePos[1] - startOffsetTop;
      var endTop = startTop + tableObj.clientHeight;		

      // Get new positon of body scroll top and keep it in bounds
      var newTop =(document.documentElement.scrollTop&gt;0) ? document.documentElement.scrollTop : document.body.scrollTop;
      if (newTop &lt; startTop) newTop = startTop;
      if (newTop &gt; endTop) newTop = endTop;

      // Move the title to new postion
      var titleObj = document.getElementById(titleID);
      if (newTop &gt; startTop &amp;&amp; newTop &lt; endTop) {

        // Display &quot;Title&quot; if it is not all ready being displayed
        if (titleObj.style.display != 'block') titleObj.style.display='block';

        // Apply offset to get newTop position
        newTop = newTop + startOffsetTop;

        // Apply Ease-In effect
        easeInWanted=true;
        if (easeInWanted) {

          // Get current location and get the difference from where it's
          // at to where you want it to go
          oldTop = parseInt(titleObj.style.top);
          topDiff=newTop-oldTop; 

          // Calaculate how far you want to move it - then set that to new postion
          moveTop=0;
          if ( (topDiff &lt; (-1) ) || (topDiff &gt; (1) ) ) { moveTop=Math.round(topDiff/3);}
          newTop = oldTop + moveTop;
        }

      	// Move to new top position
      	if (newTop &lt; 0) newTop = 0;
      	titleObj.style.top = newTop + &quot;px&quot;;
      } else {
        // Else hide &quot;Title&quot; if it is not all ready hidden
        if (titleObj.style.display != 'none') {
          titleObj.style.display='none';
          titleObj.style.top = &quot;0px&quot;;
          titleObj.style.zIndex=&quot;1&quot;;
        }
      }

    }

    // Execute this function again in 40 milliseconds (thousandths of a second)
    cmd = &quot;floatTitleLoop('&quot; + tableID + &quot;','&quot; + titleID + &quot;','&quot; + cnt + &quot;')&quot;;
    floatTitleTimer[cnt] = window.setTimeout(cmd, 40); 

  }

  //////////////////////////////////////////////////////////////////////////////
  // FindPosition - find the Top and Left postion of an object on the page
  //  @param obj - object of element whose position needs to be found
  //  @return array - Array whoose first eleemnt is the left postion and whoose
  //                  second is the top position
  //////////////////////////////////////////////////////////////////////////////

  function FindPosition(obj) {
    // Figure out where the obj object is in the page by adding
    // up all the offsets for all the containing parent objects
    if (obj == null) return [0,0];

    // Assign the obj object to a temp variable
    tmpObj = obj;

    // Get the offsets for the current object
    var obj_left = tmpObj.offsetLeft;
    var obj_top = tmpObj.offsetTop;

    // If the current object has a parent (ie contained in a table, div, etc..)
    if (tmpObj.offsetParent) {

      // Loop through all the parents and add up their offsets
      // The while loop will end when no more parents exist and a null is returned
      while (tmpObj = tmpObj.offsetParent) {
      	obj_left += tmpObj.offsetLeft;
      	obj_top += tmpObj.offsetTop;
      }
    }
    return [obj_left , obj_top];
  }

  //////////////////////////////////////////////////////////////////////////////
  // Start floating titles after window finishes loading
  ////////////////////////////////////////////////////////////////////////////// 

  window.onload = startFloatTitle;

  //////////////////////////////////////////////////////////////////////////////
  // Start floating titles when window is resized
  ////////////////////////////////////////////////////////////////////////////// 

  window.onresize = startFloatTitle;</pre>
]]></content:encoded>
			<wfw:commentRss>http://stansight.com/WordPress/2008/07/29/floating-table-titles/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Fixed Table Head</title>
		<link>http://stansight.com/WordPress/2008/07/03/fixed-table-head/</link>
		<comments>http://stansight.com/WordPress/2008/07/03/fixed-table-head/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 11:12:35 +0000</pubDate>
		<dc:creator>Stan Slaughter</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[cascading stylesheets]]></category>
		<category><![CDATA[Fixed Head]]></category>
		<category><![CDATA[Fixed Titles]]></category>
		<category><![CDATA[Freeze Panes]]></category>
		<category><![CDATA[scrollable body]]></category>
		<category><![CDATA[Scrollable Table]]></category>
		<category><![CDATA[Table Scroll]]></category>

		<guid isPermaLink="false">http://stansight.com/WordPress/2008/07/03/fixed-table-head/</guid>
		<description><![CDATA[Scrollable Table Body with a Fixed Table Heading Tested to work in Firefox 3 and Internet Explorer 7. Safari users may want to check out Floating Table Titles There is no HTML or CSS standard tag or property that lets you freeze the title row of a table in place while allowing the body to [...]]]></description>
			<content:encoded><![CDATA[<p></p>
<h3>Scrollable Table Body with a Fixed Table Heading<br />
<span style="font-size:10px">Tested to work in Firefox 3 and Internet Explorer 7. Safari users may want to check out <a href="http://stansight.com/WordPress/2008/07/29/floating-table-titles/">Floating Table Titles</a> </span><br />
</h3>
<p>There is no HTML or CSS standard tag or property that lets you freeze the title row of a table in place while allowing the body to scroll up and down.</p>
<p>Like this:</p>
<div class="FixedTableHead">
<table style="height:75px;">
<thead>
<tr>
<td>Title #1</td>
<td>Title #2&#8230;.</td>
<td>Title #3&#8230;&#8230;.</td>
<td>#4</td>
</tr>
</thead>
<tbody>
<tr>
<td>Item 1&#8230;&#8230;&#8230;..</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
</tbody>
</table>
</div>
<p>In response to this I created the &#8220;FixedTableHead&#8221; CSS class.<span id="more-27"></span></p>
<p>I wanted a CSS solution that was easy to use.  Other solutions I ran across on the web tended to be inflexible and hard to implement in real world situations.  They had you hard coding table widths and heights in multiple locations in the CSS.  This can be a real pain if you want to use it for multiple tables that vary in size.</p>
<p>&#8220;FixedTableHead&#8221; handles multiple tables of different sizes on the same page.  I attempted to keep the HTML mark-up as simple as possible. All you need do is to assign a single CSS class name to a DIV that surrounds your table then assign a height you want the table to be as an embedded style. That&#8217;s it.</p>
<p>Example:</p>
<pre class="brush: xml;">
&lt;div class=&quot;FixedTableHead&quot;&gt;
	&lt;table style=&quot;height:100px;&quot;&gt;
		&lt;thead&gt;
			...
		&lt;/thead&gt;
		&lt;tbody&gt;
			...
		&lt;/tbody&gt;
	&lt;/table&gt;
&lt;/div&gt;
</pre>
<p>This has been tested to work in IE7, Firefox 2 and Firefox 3.  As long as the table uses a THEAD and a TBODY then the header rows will remain fixed in place while the content in the table body scrolls up or down.</p>
<p></p>
<h3>Height: 75px; Width: Nothing &#8211; What ever the content sizes it to</h3>
<p></p>
<div class="FixedTableHead">
<table style="height:75px;">
<thead>
<tr>
<td>Title #1</td>
<td>Title #2&#8230;.</td>
<td>Title #3&#8230;&#8230;.</td>
<td>#4</td>
</tr>
</thead>
<tbody>
<tr>
<td>Item 1&#8230;&#8230;&#8230;..</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
</tbody>
</table>
</div>
<p></p>
<h3>Height: 100px; Width: 400px;</h3>
<p></p>
<div class="FixedTableHead">
<table style="height:100px; width:400px;">
<thead>
<tr>
<td>Title #1</td>
<td>Title #2&#8230;.</td>
<td>Title #3&#8230;&#8230;.</td>
<td>#4</td>
</tr>
</thead>
<tbody>
<tr>
<td>Item 1&#8230;&#8230;&#8230;..</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
</tbody>
</table>
</div>
<p></p>
<h3>Height: 200px; Width:600px;</h3>
<p></p>
<div class="FixedTableHead">
<table style="height:200px; width:600px;">
<thead>
<tr>
<td>Title #1</td>
<td>Title #2&#8230;.</td>
<td>Title #3&#8230;&#8230;.</td>
<td>#4</td>
</tr>
</thead>
<tbody>
<tr>
<td>Item 1&#8230;&#8230;&#8230;..</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
</tbody>
</table>
</div>
<p></p>
<h3>Height: 60px; Width:200px;</h3>
<p></p>
<div class="FixedTableHead">
<table style="height:60px; width:200px;">
<thead>
<tr>
<td>Title #1</td>
<td>Title #2&#8230;.</td>
<td>Title #3&#8230;&#8230;.</td>
<td>#4</td>
</tr>
</thead>
<tbody>
<tr>
<td>Item 1&#8230;&#8230;&#8230;..</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
<tr>
<td>Item 1</td>
<td>Item 2</td>
<td>Item 3</td>
<td>Item 4</td>
</tr>
<tr>
<td>Itemb5</td>
<td>Item 6</td>
<td>Item 7</td>
<td>Item 8</td>
</tr>
</tbody>
</table>
</div>
<p></p>
<h3>CSS Code:</h3>
<pre class="brush: css;">
/* DIV container around table to constrict the height for IE (IE ignores the tbody height style) */
div.FixedTableHead {
	overflow-y:auto;
	margin: 0px;
	padding: 0px;
	border: expression( '1px solid black');

	/* this fixes IE so container width is same as table width */
	width: expression( (this.childNodes[0].clientWidth + 17) + 'px' );

	/* This fixes IE so the container height is table height plus the height of the header */
	height: expression( (parseInt(this.childNodes[0].style.height) +
						 this.childNodes[0].childNodes[1].offsetTop + 1) +'px' );
}

/* Get rid of table cellspacing */
div.FixedTableHead table {
	border-spacing: 0px;
	border-collapse: collapse;
}

/* Get rid of table cellspacing */
div.FixedTableHead table td {
	margin: 0px;
}

/* Scrollable Content */
.FixedTableHead table tbody {
	height:100%;
	overflow-x:hidden;
	overflow-y:auto;
	border: 1px solid black;
}

.FixedTableHead table tbody tr {
	height: auto;
	white-space: nowrap;
}

/* Prevent Mozilla scrollbar from hiding right-most cell content */
.FixedTableHead table tbody tr td:last-child {
	padding-right: 20px;

}

/* Fixed Header for IE (firefox uses the tbody overflow assignment, which is ignored by IE)   */
/* Note: In IE an element with a position property set to relative and is a child of         */
/* an element that has an overflow property set, the relative value translates into fixed.    */
.FixedTableHead table thead tr {
	position: relative;
	height: auto;
	/* this fixes IE header jumping bug when mousing over rows in the tbody */
	top: expression( this.parentNode.parentNode.parentNode.scrollTop + 'px' );
}

/* Formatting Header Row */
.FixedTableHead table thead tr td {
	color: white;
	background-color: #303433;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://stansight.com/WordPress/2008/07/03/fixed-table-head/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>Trim Spaces</title>
		<link>http://stansight.com/WordPress/2007/11/08/trim-spaces/</link>
		<comments>http://stansight.com/WordPress/2007/11/08/trim-spaces/#comments</comments>
		<pubDate>Thu, 08 Nov 2007 16:51:06 +0000</pubDate>
		<dc:creator>Stan Slaughter</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[RegExp]]></category>
		<category><![CDATA[Regular expression]]></category>
		<category><![CDATA[substring]]></category>
		<category><![CDATA[trim space]]></category>
		<category><![CDATA[trimspace]]></category>
		<category><![CDATA[trimspaces]]></category>

		<guid isPermaLink="false">http://stansight.com/WordPress/2007/11/08/trim-spaces/</guid>
		<description><![CDATA[Sometimes you&#8217;ll have unnecessary spaces at the beginning or end of a character string that you wish to remove. For some unknown reason a trim space method or function was not included as part of the JavaScript language, even though this comes standard in most other programming languages. Well, here are two different solutions for [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you&#8217;ll have unnecessary spaces at the beginning or end of a character string that you wish to remove.  For some unknown reason a trim space method or function was not included as part of the JavaScript language, even though this comes standard in most other programming languages.</p>
<p>Well, here are two different solutions for you.  The first one uses straight forward &#8220;while loop&#8221; approach.    Each character in the front of the string is checked. if it is a space then the string is changed to exclude it from the front.  It does this until a non-space character is reached.  The same is then done for the end of the string.  Though in this case the string is searched from right to left. <span id="more-18"></span></p>
<h2>First Solution</h2>
<pre class="brush: jscript;">function trimSpace(sString) {
 while (sString.substring(0,1) == ' ') {
  sString = sString.substring(1, sString.length);
 }
 while (sString.substring(sString.length-1, sString.length) == ' ') {
  sString = sString.substring(0,sString.length-1);
 }
 return sString;
}</pre>
<p>Example of how it would be used</p>
<pre class="brush: jscript;">X = '  Bob   ';
X = trimSpace(X);
//
// X is now equal to 'Bob'
//</pre>
<h2>The Second Solution</h2>
<p>This next solution is both simpler and yet trickier for those who are not used to Regular Expressions in JavaScript.  </p>
<blockquote><p>Regular expressions are a form of pattern matching that you can apply on textual content. Take for example the DOS wildcards ? and * which you can use when you&#8217;re searching for a file. That is a kind of very limited subset of RegExp. For instance, if you want to find all files beginning with &#8220;fn&#8221;, followed by 1 to 4 random characters, and ending with &#8220;ht.txt&#8221;, you can&#8217;t do that with the usual DOS wildcards. RegExp, on the other hand, could handle that and much more complicated patterns&#8230;.<a href="http://www.javascriptkit.com/javatutors/redev.shtml" title="http://www.javascriptkit.com/javatutors/redev.shtml">more</a></p></blockquote>
<p>The scope of this article is not to discuss Regular Expression syntax in detail, for that please follow the link posted above.  I simply want to show how powerful they can be by demonstrating their use in removing leading and trailing spaces from a string.</p>
<pre class="brush: jscript;">function trimSpace(s) {

  var SpcEnds = new RegExp(&quot;^\\s*|\\s*$&quot;, &quot;g&quot;); // Create Regular expression
  s = s.replace(SpcEnds, &quot;&quot;);                   // Remove leading or trailing spaces.

  return s;
}</pre>
<p>It would be called and used in the same way as the first solution.</p>
<h2>Conclusion</h2>
<p>Which solution should you use?  </p>
<p>Note: Regardless of the number of lines used, neither solution executes measurably faster than the other.</p>
<p><strong>Solution 1</strong>, the traditional while loop approach, is easy to read and this will allow for most developers to understand it more readily.  This in turn makes it easier to debug if issues arise.</p>
<p>But &#8211; More code does offer more complexity.  It&#8217;s easy to understand, yet introduces more lines of code which can lead to some inflexibility.  </p>
<p><strong>Solution 2</strong>, the Regular Expression approach, has the advantage of offering even more advanced pattern matching functionality if later on you needed to expand this to remove embedded spaces as well, or replace the space with a different character.</p>
<p>But &#8211; this flexibility comes at the cost of clarity which in term can impact the maintainability of the code.   It&#8217;s powerful, yet relatively obscure. </p>
<p>Which should you use?   Well, that decision will be up to you. </p>
]]></content:encoded>
			<wfw:commentRss>http://stansight.com/WordPress/2007/11/08/trim-spaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Frameworks &#8211; Time to take them seriously?</title>
		<link>http://stansight.com/WordPress/2007/11/06/javascript-frameworks-time-to-take-them-seriously/</link>
		<comments>http://stansight.com/WordPress/2007/11/06/javascript-frameworks-time-to-take-them-seriously/#comments</comments>
		<pubDate>Tue, 06 Nov 2007 16:08:50 +0000</pubDate>
		<dc:creator>Stan Slaughter</dc:creator>
				<category><![CDATA[Design Talks]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[JavaScript Frameworks]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Scriptaculous]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://stansight.com/WordPress/2007/11/06/javascript-frameworks-time-to-take-them-seriously/</guid>
		<description><![CDATA[Have JavaScript Frameworks now hit a level of maturity that a business can feel confident that if they use them that code will not be outdated and impossible to maintain in less than a year? JavaScript Frameworks are cross-browser user interface JavaScript libraries designed to make it easier to develop complex Graphical User Interfaces (GUI&#8217;s) [...]]]></description>
			<content:encoded><![CDATA[<p>Have JavaScript Frameworks now hit a level of maturity that a business can feel confident that if they use them that code will not be outdated and impossible to maintain in less than a year?</p>
<p>JavaScript Frameworks are cross-browser user interface JavaScript libraries designed to make it easier to develop complex Graphical User Interfaces (GUI&#8217;s) for web pages.</p>
<p>I&#8217;ve tended to stay away from JavaScript Frameworks.  My view was that in an attempt to be generic libraries they have introduced complexity, making it harder to implement and debug.  Frankly, I did not want to spend a lot of time learning proprietary syntax to a library which may not be around all that long.  There seemed to be a new flavor-of-the month library coming out ever other month.  Here is just a small list of the currently most popular:</p>
<p>The Yahoo! User Interface (YUI) &#8211; <a href="http://developer.yahoo.com/yui/">http://developer.yahoo.com/yui/</a><br />
Prototype &#8211; <a href="http://www.prototypejs.org/">http://www.prototypejs.org/</a><br />
ExtJS &#8211; <a href=" http://extjs.com/">http://extjs.com/ </a><br />
script.aculo.us &#8211; <a href="http://script.aculo.us/">http://script.aculo.us/</a><br />
Dojo &#8211; <a href="http://dojotoolkit.org/">http://dojotoolkit.org/</a><br />
jQuery &#8211; <a href="http://jquery.com/">http://jquery.com/</a><br />
mootools &#8211; <a href="http://mootools.net/">http://mootools.net/</a></p>
<p>And the list goes on &#8230; </p>
<p>BUT &#8211; Looking over some of the newer frameworks &#8211; such as Ext JS 2.0 : <a href="http://extjs.com/">http://extjs.com/</a> it certainly looks like a lot of functionality and maturity is starting to creep into them.</p>
<p>So &#8211;  Have JavaScript Frameworks now hit a level of maturity that a business can feel confident that if they use them that code will not be outdated and impossible to maintain in less than a year?</p>
<p>As a developer is it getting to the point where JavaScript Frameworks need to be taken more seriously? </p>
]]></content:encoded>
			<wfw:commentRss>http://stansight.com/WordPress/2007/11/06/javascript-frameworks-time-to-take-them-seriously/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CSS Text Drop Shadow</title>
		<link>http://stansight.com/WordPress/2007/10/28/text-drop-shadows/</link>
		<comments>http://stansight.com/WordPress/2007/10/28/text-drop-shadows/#comments</comments>
		<pubDate>Sun, 28 Oct 2007 14:38:01 +0000</pubDate>
		<dc:creator>Stan Slaughter</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[cascading stylesheets]]></category>
		<category><![CDATA[css drop shadow]]></category>
		<category><![CDATA[Drop Shadow]]></category>
		<category><![CDATA[drop shadow effect]]></category>
		<category><![CDATA[drop shadow text]]></category>
		<category><![CDATA[how make]]></category>
		<category><![CDATA[shadow text]]></category>
		<category><![CDATA[text shadow effect]]></category>

		<guid isPermaLink="false">http://stansight.com/WordPress/2007/10/28/text-drop-shadows/</guid>
		<description><![CDATA[How to add cross browser drop shadow to text without the use of images using cascading stylesheets and non-obtrusive JavaScript.]]></description>
			<content:encoded><![CDATA[<p><script src="/DropShadow.js"></script></p>
<h1 class="dropshadow" style="color:white;">CSS Text Drop Shadow</h1>
<p>How to add cross browser drop shadow to text without the use of images using CSS and non-obtrusive JavaScript.</p>
<p>I&#8217;ve wanted to use drop shadows on text for quite awhile.  Unfortunately there is just no easy way to do this on a web page without the use of a graphics program and I did not want to make a graphics image every single time I wanted to throw a drop shadow around a piece of text.</p>
<h2>The Problem</h2>
<p>I searched for a pure CSS approach without much luck.  Internet Explorer has a CSS filter that makes dropshadows, but I wanted something that would work in both Firefox (my browser of choice) and Internet Explorer (Note: I&#8217;ve been told this solution works in Opera and Safari as well).  </p>
<p>I have seen a few people fake a text drop shadow effect by typing the text twice.  They used CSS to place one on top of each other, with slight offsets, making the bottom one black so it resembled a hard edged drop shadow.</p>
<p>It&#8217;s a neat idea, with a few problems.  </p>
<ol>
<li>The drop shadow has a hard edge and looks pretty 1980&#8242;ish</li>
<li>It&#8217;s a pain to set up.  You have to type all your text twice, put each in separate DIV tags, position each separately or at least create two different CSS classes to position them for you.</li>
</ol>
<p>Most people try this once and then drop it.  It&#8217;s simply too cumbersome to use.  I thought the concept had potential, but the problems had to be addressed.</p>
<h2>A Solution</h2>
<p>What I have come up with is a JavaScript function which runs automatically when your web page finishes loading.  It looks through your web page and anywhere it sees an element with the class &#8216;dropshadow&#8217; it will add a text drop shadow effect to it.</p>
<h4>Examples</h4>
<pre class="brush: xml;">&lt;h1 class=&quot;dropshadow&quot;&gt;I am an H1 element with Drop Shadow&lt;/h1&gt;</pre>
<h1 class="dropshadow">I am an H1 element with Drop Shadow</h1>
<pre class="brush: xml;">&lt;div class=&quot;dropshadow&quot; style=&quot;color:white; font-family:Impact; font-size:4em;&quot;&gt;White Impact font in DIV&lt;/div&gt;</pre>
<div class="dropshadow" style="color:white; font-family:Impact; font-size:4em;">White Impact font in DIV</div>
<p>A link to further examples: <a href='http://www.stansight.com/DropShadow2.html'>http://www.stansight.com/DropShadow2.html</a></p>
<hr style="width:50%; margin:30px auto;" />
<h2>Getting it to work</h2>
<h4>CSS Class</h4>
<p>All you need to get this work is to define this minimal bit of CSS between the HEAD tags of your page:
<pre class="brush: css;">
  &lt;style type=&quot;text/css&quot;&gt;
  .dropshadow {
     position: relative;
     z-index:10;
  }
  &lt;/style&gt;</pre>
<h4>JavaScript</h4>
<p>Place the &#8220;DropShadow.js&#8221; code in a file called DropShadow.js which is then included in your web page by placing this bit of code between the HEAD tags of you page:</p>
<pre class="brush: jscript;">&lt;script src=&quot;DropShadow.js&quot;&gt;&lt;/script&gt;</pre>
<p><strong>JavaScript DropShadow.js</strong></p>
<p><em>Note: To make smaller drop shadows change the value of max_shadows in the CreateShadowChildren function to a smaller number.</em>
<pre class="brush: jscript;">

   function MakeDropShadow() {

     var node = document;
     var tag = '*';
     var wantedClass = 'dropshadow';

     // Build a regular expression that will search specically for 'wantedClass'
     var pattern = new RegExp(&quot;(^|\\s)&quot;+wantedClass+&quot;(\\s|$)&quot;);

     // Scan through all tag elements in the document
     var scan_elem = node.getElementsByTagName(tag);
     for (i = 0; i &lt; scan_elem.length; i++) {

       // If element has a class of 'wantedClass'
       if (pattern.test(scan_elem[i].className) ) {

         // Get the value from the element
         var text_value = scan_elem[i].innerHTML;

         // Create Shadow Children for this element
         CreateShadowChildren(scan_elem[i],text_value);
       }
     } // End for loop
   }

  function CreateShadowChildren(shadow_element,shadow_value) {

   var top_pos = .5;
   var left_pos = .5;

   // Assign starting color (in Hex notation) for the Red, Green, and Blue
   // Components (when they all have the same value you will alwys get a gray color).
   // For lighter shadows start with a &quot;lighter&quot; color of 66, 77, 88 99, aa, bb, etc..
   var starting_color = '44';
   var cRed = parseInt(starting_color,'16');
   var cGreen = parseInt(starting_color,'16');
   var cBlue = parseInt(starting_color,'16');

   // Set the max number of shadow elements to create.
   // This should never be set larger than the Z-Index value of dropshadow class
   var max_shadows = 10; 

   // Calculate color increament based on range of gray colors (from starting_color to
   // the lighest gray color of #fefefe) and max number of shadows you want
   var color_inc =  parseInt(( parseInt('fe','16') - parseInt(starting_color,'16') ) / max_shadows,'10');

   for (j = 1; j &lt;= max_shadows; j++) {

     // Build full color Hex string from it's individual RGB values
     var full_color_value = cRed.toString(16) + cGreen.toString(16) + cBlue.toString(16);

     // Create a Shadow DIV
     var shadow_div = document.createElement('div');

     //  Add the shadow_value to Shadow DIV
     shadow_div.innerHTML = shadow_value;

     // Style Shadow DIV
     shadow_div.style.width=shadow_element.offsetWidth + &quot;px&quot;;
     shadow_div.style.color = '#' + full_color_value;
     shadow_div.style.borderColor = '#' + full_color_value;
     shadow_div.style.display = &quot;block&quot;;
     shadow_div.style.position = &quot;absolute&quot;;
     shadow_div.style.top = top_pos + &quot;px&quot;;
     shadow_div.style.left = left_pos + &quot;px&quot;;
     shadow_div.style.zIndex = (-1) * j;

     // Apppend Shadow DIV to shadow element
     shadow_element.appendChild(shadow_div);

     // Increment positons and shadows individual RGB color values
     top_pos += .5;
     left_pos += .5;
     cRed += color_inc;
     cGreen += color_inc;
     cBlue += color_inc;
   }

  }

 // Run the MakeDropShadow function when the page finishes loading
 window.onload = MakeDropShadow;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://stansight.com/WordPress/2007/10/28/text-drop-shadows/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Validate Phone Number</title>
		<link>http://stansight.com/WordPress/2007/10/18/validate-phone-number/</link>
		<comments>http://stansight.com/WordPress/2007/10/18/validate-phone-number/#comments</comments>
		<pubDate>Thu, 18 Oct 2007 19:33:38 +0000</pubDate>
		<dc:creator>Stan Slaughter</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[phone number]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://stansight.com/WordPress/?p=16</guid>
		<description><![CDATA[Simple Phone number validation function that returns &#8220;true&#8221; if the phone number is in the format 555-555-5555 Useful when validating input from a form prior to writing it to a database. (Note the use of regular expressions used to validate the formatting) /** * This function validates that the provided string is a phone number [...]]]></description>
			<content:encoded><![CDATA[<p>Simple Phone number validation function that returns &#8220;true&#8221; if the phone number is in the format 555-555-5555</p>
<p>Useful when validating input from a form prior to writing it to a database.</p>
<p>(Note the use of regular expressions used to validate the formatting)</p>
<pre class="brush: jscript;">/**
*  This function validates that the provided string is a phone number with
*  the format of 555-555-5555
*
*  @param  s the String containing the phone number
*  @return boolean
*/
function isValidPhoneNumber(s) {

 // See if it is empty
 if (s.length == 0) {
  alert(&quot;Please enter a value for the phone number.&quot;);
  return false;
 }

 // Make Regular expression for checking for correct phone number format
 rePhoneNumber = new RegExp(/^[1-9]\d{2}\-\d{3}\-\d{4}$/);

 // Test string using regular expression (return false if it fails)
 if (!rePhoneNumber.test(s)) {
  alert(&quot;Phone Number Must Be Entered As: 555-555-5555&quot;);
  return false;
 }

 return true;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://stansight.com/WordPress/2007/10/18/validate-phone-number/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.100 seconds -->
