<?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</title>
	<atom:link href="http://stansight.com/WordPress/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>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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 cookie
// [...]]]></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>0</slash:comments>
		</item>
		<item>
		<title>Well Designed User Interface</title>
		<link>http://stansight.com/WordPress/2009/02/16/well-desgined-user-interface/</link>
		<comments>http://stansight.com/WordPress/2009/02/16/well-desgined-user-interface/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 20:52:58 +0000</pubDate>
		<dc:creator>Stan Slaughter</dc:creator>
				<category><![CDATA[Design Talks]]></category>

		<guid isPermaLink="false">http://stansight.com/WordPress/2009/02/16/well-desgined-user-interface/</guid>
		<description><![CDATA[&#8220;A user interface is well-designed when the program behaves exactly how the user thought it would.&#8221;
I love that quote.  It seems to sum up the entirety of what a good user interface is.  It&#8217;s not fancy graphics or cutting edge layouts.  It&#8217;s providing people with what they need, when they need it. [...]]]></description>
			<content:encoded><![CDATA[<p><em>&#8220;A user interface is well-designed when the program behaves exactly how the user thought it would.&#8221;</em></p>
<p>I love that quote.  It seems to sum up the entirety of what a good user interface is.  It&#8217;s not fancy graphics or cutting edge layouts.  It&#8217;s providing people with what they need, when they need it.  The best user interfaces are those that are so seamless that the casual user does not even notice them.<span id="more-52"></span> </p>
<p><a href="http://www.google.com/finance?q=Google"><img src='http://stansight.com/WordPress/wp-content/uploads/2009/02/google.gif' alt='Google Finance' style="border:0px; float:right;margin:5px 0 5px 5px;"/></a>A good example of this is <a href="http://www.google.com/finance?q=Google">Google&#8217;s Finance page</a>.  This is an information rich page.  Behaving as a casual user would expect a finance page to behave.  One simple page providing all you need to know at a glance.</p>
<p>In fact, just looking at it, it is hard to point to any user interface at all.  It appears to be nothing more than static information.  Until you notice that the stock price is not a static number, but changing every few seconds (changing the web page title to match).  Until you notice that the main stock graph is has flags on it that can be clicked to take you to news articles, or blogs about the company.  Until you notice that mousing over the &#8220;Officers and directors&#8221; names at the bottom right of the page gives you expanded biographies and links to that officers reported salary and yearly compensations. Until&#8230;</p>
<p>You get the point.  A good user interface does not jump up and down and try to get your attention, possibly distracting users from the information you really want them to focus on.  Instead, it behaves how a user expects it to, providing more in depth behavior in seamless, unobtrusive ways.  Ways that do not clutter up or interfere with the basic task.</p>
<p><b>What They Expect</b></p>
<p>But &#8211; how do you know what a user expects ?  Well, you can try to think like a user.  Pretend that you are a customer and try to figure out what you would want, and how you would react to different situations.  This approach works, but is not optimal.  It&#8217;s too easy to forget what it is like to know absolutely nothing about the project.  For that, you will need some more people.</p>
<p>Grab people who are just walking down the hallway.  Show them a prototype or demo and give them a simple task to do.  Ask them what they think is happening.  Take notes.  Interview them using open questions.  Never tell them &#8220;how&#8221; to do things.  After you have done this with 5 or 6 people take the most common flaws (majority rules) and fix them.</p>
<p>A Well Desgined User Interface is one where a lot of hard work has gone into not making it hard for your users and customers.</p>
]]></content:encoded>
			<wfw:commentRss>http://stansight.com/WordPress/2009/02/16/well-desgined-user-interface/feed/</wfw:commentRss>
		<slash:comments>0</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 [...]]]></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 [...]]]></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 [...]]]></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>Moble Phone Detection</title>
		<link>http://stansight.com/WordPress/2008/09/05/moble-phone-detection/</link>
		<comments>http://stansight.com/WordPress/2008/09/05/moble-phone-detection/#comments</comments>
		<pubDate>Sat, 06 Sep 2008 03:30:33 +0000</pubDate>
		<dc:creator>Stan Slaughter</dc:creator>
				<category><![CDATA[Design Talks]]></category>

		<guid isPermaLink="false">http://stansight.com/WordPress/2008/09/05/moble-phone-detection/</guid>
		<description><![CDATA[Every moble phone script detection that I have run across (server side or client side) all seem to want to check user agent against a long long long long long list of values.
What&#8217;s wrong with simply checking screen width ? In my opinion there is a 99% probability that anything with a width of 640 [...]]]></description>
			<content:encoded><![CDATA[<p>Every moble phone script detection that I have run across (server side or client side) all seem to want to check user agent against a long long long long long list of values.</p>
<p>What&#8217;s wrong with simply checking screen width ? In my opinion there is a 99% probability that anything with a width of 640 or under is a mobile device.<span id="more-43"></span>   </p>
<p>Sure this will not tell anything about the capabilites of the browser (CSS/JavaScript/ect support) &#8211; but knowing it&#8217;s a cell phone would certainly give you a chance to know you have a low bandwidth device with a small screen &#8211; so don&#8217;t make them download your 1024&#215;100 jpg page banner or the 1024&#215;764 full page photos of your pet dog.</p>
]]></content:encoded>
			<wfw:commentRss>http://stansight.com/WordPress/2008/09/05/moble-phone-detection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Designing for Broadband OK</title>
		<link>http://stansight.com/WordPress/2008/08/19/design-for-broadband-ok/</link>
		<comments>http://stansight.com/WordPress/2008/08/19/design-for-broadband-ok/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 18:36:18 +0000</pubDate>
		<dc:creator>Stan Slaughter</dc:creator>
				<category><![CDATA[Design Talks]]></category>

		<guid isPermaLink="false">http://stansight.com/WordPress/2008/08/19/design-for-broadband-ok/</guid>
		<description><![CDATA[It looks like designing your website for broadband is OK now.
According to Leichtman Research broadband penetration in the US should break 90% by mid-2008.  This is based on a survey conducted in February of 2008 showing that broadband was in 57% of  U.S. households: http://www.websiteoptimization.com/bw/0802/
Personally &#8211; I&#8217;ll take the trending numbers with a [...]]]></description>
			<content:encoded><![CDATA[<p>It looks like designing your website for broadband is OK now.</p>
<p>According to Leichtman Research broadband penetration in the US should break 90% by mid-2008.  This is based on a survey conducted in February of 2008 showing that broadband was in 57% of <span id="more-42"></span> U.S. households: <a href="http://www.websiteoptimization.com/bw/0802/">http://www.websiteoptimization.com/bw/0802/</a></p>
<p>Personally &#8211; I&#8217;ll take the trending numbers with a grain of salt until they are confirmed, but this defintly shows that a majority of US households now have broadband, and I would hazard a guess that those households contain the newest and most active populace of the web surfing world.</p>
<p>So if you are designing for mid to younger audiences &#8211; go hog wild with the graphics, videos and flash.  If you are designing a geneology or quilting bee web site &#8211; stick with small graphics and text for those dial up users.</p>
<p>But &#8211; in all cases &#8211; follow good design principles.  Remember more is not always better: <a href="http://www.fastcompany.com/magazine/100/beauty-of-simplicity.html">http://www.fastcompany.com/magazine/100/beauty-of-simplicity.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://stansight.com/WordPress/2008/08/19/design-for-broadband-ok/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 exsting titles and &#8220;fix&#8221; [...]]]></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>14</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 scroll [...]]]></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>27</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>
	</channel>
</rss>

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