Email This Post Email This Post Print This Post Print This Post

Fixed Table Head

Thu, Jul 3, 2008 – 5:12 am by Stan Slaughter

Scrollable Table Body with a Fixed Table Heading

There is no current HTML or CSS standard supported across all browsers that lets you freeze the title row of a table in place while allowing the body to scroll up and down.

Like this:

Title #1 Title #2…. Title #3……. #4
Item 1……….. Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8

To me this is a very strange lack. It’s a common to want to fix your titles in place for long tables. The concept is so old that it has been supported in products like Microsofts Excel as “freeze panes” almost since day 1.

In response to this I decided to create the “FixedTableHead” CSS class.

I wanted a CSS solution that was easy to use. The 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.

“FixedTableHead” 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’s it.

Example:


<div class="FixedTableHead">
	<table style="height:100px;">
		<thead>
			...
		</thead>
		<tbody>
			...
		</tbody>
	</table>
</div>

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.

Height: 75px; Width: Nothing - What ever the content sizes it to

Title #1 Title #2…. Title #3……. #4
Item 1……….. Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8

Height: 100px; Width: 400px;

Title #1 Title #2…. Title #3……. #4
Item 1……….. Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8

Height: 200px; Width:600px;

Title #1 Title #2…. Title #3……. #4
Item 1……….. Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8

Height: 60px; Width:200px;

Title #1 Title #2…. Title #3……. #4
Item 1……….. Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8
Item 1 Item 2 Item 3 Item 4
Itemb5 Item 6 Item 7 Item 8

CSS Code:


<style type='text/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;
}
</style>
Email This Post Email This Post Print This Post Print This Post

Trim Spaces

Thu, Nov 8, 2007 – 10:51 am by Stan Slaughter

Sometimes you’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 you. The first one uses straight forward “while loop” 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.

First Solution

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;
}

Example of how it would be used

X = '  Bob   ';
X = trimSpace(X);
//
// X is now equal to 'Bob'
//

The Second Solution

This next solution is both simpler and yet trickier for those who are not used to Regular Expressions in JavaScript.

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’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 “fn”, followed by 1 to 4 random characters, and ending with “ht.txt”, you can’t do that with the usual DOS wildcards. RegExp, on the other hand, could handle that and much more complicated patterns….more

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.

function trimSpace(s) {

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

  return s;
}

It would be called and used in the same way as the first solution.

Conclusion

Which solution should you use?

Note: Regardless of the number of lines used, neither solution executes measurably faster than the other.

Solution 1, 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.

But - More code does offer more complexity. It’s easy to understand, yet introduces more lines of code which can lead to some inflexibility.

Solution 2, 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.

But - this flexibility comes at the cost of clarity which in term can impact the maintainability of the code. It’s powerful, yet relatively obscure.

Which should you use? Well, that decision will be up to you.

Email This Post Email This Post Print This Post Print This Post

JavaScript Frameworks - Time to take them seriously?

Tue, Nov 6, 2007 – 10:08 am by Stan Slaughter

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’s) for web pages.

I’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:

The Yahoo! User Interface (YUI) - http://developer.yahoo.com/yui/
Prototype - http://www.prototypejs.org/
ExtJS - http://extjs.com/
script.aculo.us - http://script.aculo.us/
Dojo - http://dojotoolkit.org/
jQuery - http://jquery.com/
mootools - http://mootools.net/

And the list goes on …

BUT - Looking over some of the newer frameworks - such as Ext JS 2.0 : http://extjs.com/ it certainly looks like a lot of functionality and maturity is starting to creep into them.

So - 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?

As a developer is it getting to the point where JavaScript Frameworks need to be taken more seriously?

Email This Post Email This Post Print This Post Print This Post

Who cares about Firefox?

Mon, Oct 29, 2007 – 9:08 am by Stan Slaughter

Who cares about Firefox?

Have you ever noticed that those people who vehemently argue for writing pages which work in Firefox frequently design pages which are totally unusable if viewed on a 800×600 video screen?

Yet almost the same number of people who use Firefox, 13% of the browser market as of September 2007, (http://www.thecounter.com/stats/2007/September/browser.php) browse the web on a computer with a video screen set to a 800×600 resolution (10% of the browser market: http://www.thecounter.com/stats/2007/September/res.php)

So - Why the lack of (loud) public support from the web design community?

Is it because web designers are loathed to give up their big header graphic images and navigation buttons which take up half the screen even on larger screens ? Is it because shouting for the cause of the 800×600 display can’t drum up the rabid fan-boyism of “stickin-it-to-microsoft” that supporters of the Firefox browser enjoy?

Or is it simply that the young web designer crowd do not have friends which browse the web at 800×600 and therefore do not consider it important (after all if their friends are not doing it why bother to design for it) ?

Email This Post Email This Post Print This Post Print This Post

Text Drop Shadows

Sun, Oct 28, 2007 – 8:38 am by Stan Slaughter

Text Drop Shadows

How to add cross browser drop shadow to text without the use of images using cascading stylesheets and non-obtrusive JavaScript.

I’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.

The Problem

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’ve been told this solution works in Opera and Safari as well).

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.

It’s a neat idea, with a few problems.

  1. The drop shadow has a hard edge and looks pretty 1980′ish
  2. It’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.

Most people try this once and then drop it. It’s simply too cumbersome to use. I thought the concept had potential, but the problems had to be addressed.

A Solution

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 ‘dropshadow’ it will add a text drop shadow effect to it.

Examples

<h1 class="dropshadow">I am an H1 element with Drop Shadow</h1>

I am an H1 element with Drop Shadow

<div class="dropshadow" style="color:white; font-family:Impact; font-size:4em;">White Impact font in DIV</div>
White Impact font in DIV

A link to further examples: http://www.stansight.com/DropShadow2.html


Getting it to work

CSS Class

All you need to get this work is to define this minimal bit of CSS between the HEAD tags of your page:


  <style type="text/css">
  .dropshadow {
     position: relative;
     z-index:10;
  }
  </style>

JavaScript

Place the “DropShadow.js” 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:

<script src="DropShadow.js"></script>

JavaScript DropShadow.js

Note: To make smaller drop shadows change the value of max_shadows in the CreateShadowChildren function to a smaller number.


   function MakeDropShadow() {

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

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

     // Scan through all tag elements in the document
     var scan_elem = node.getElementsByTagName(tag);
     for (i = 0; i < 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 "lighter" 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 <= 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 + "px";
     shadow_div.style.color = '#' + full_color_value;
     shadow_div.style.borderColor = '#' + full_color_value;
     shadow_div.style.display = "block";
     shadow_div.style.position = "absolute";
     shadow_div.style.top = top_pos + "px";
     shadow_div.style.left = left_pos + "px";
     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;
Email This Post Email This Post Print This Post Print This Post

CSS for Beginners

Tue, Oct 23, 2007 – 1:37 pm by Stan Slaughter

Here are some links that may be of some help for those just starting out with Cascading Style Sheets. They are among the best links on the web not only for those who are just starting out, but for those who need a CSS resource to refer back to later on.

http://www.cssbasics.com/ - Learn everything you ever wanted to know about the basics of CSS
http://www.w3schools.com/css/ - CSS tutorials, references, examples for web building
http://www.htmldog.com/guides/cssbeginner/ - CSS Beginner Tutorial
BrainJar.com: Using Style Sheets - Overview of Cascading Style Sheets
Web Design 101 Articles - Each article covers a single subject in depth

Email This Post Email This Post Print This Post Print This Post

Validate Phone Number

Thu, Oct 18, 2007 – 1:33 pm by Stan Slaughter

Simple Phone number validation function that returns “true” 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 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("Please enter a value for the phone number.");
  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("Phone Number Must Be Entered As: 555-555-5555");
  return false;
 }

 return true;
}
Email This Post Email This Post Print This Post Print This Post

Tooltips for Forms

Wed, Oct 17, 2007 – 2:25 pm by Stan Slaughter

Create a tooltip for you web forms !

A tooltip is a small box containing which appears when you move your mouse over a hyperlink:
Hover over me to see

This visual element is useful in supplying additional information to the user without needing to take up addtional space on the screen. It is very easy to implement as well. All you need do is to use the “title” property of the anchor tag to display the addtional text message:

<a href="#" title="This is a standard tooltip">Hover over me to see</a>

One problem with the standard tooltip is that you can’t control how long the tool tip stays visible so you are limited to using very short messages.

Another problem is that using “title” in other HTML elements, such as an INPUT tag for a form, the implementation is not exactly what you would want to happen. It shows up if the user thinks to “hover” the mouse over the input field, but will not show up if they simply tab into it or move their mouse to another area of the screen.

That’s too bad because a forms input tag is the perfect place to have a tooltip. It could be used as a mini-help note. Letting the user know what the field is for, what format is expected, etc..

Since I do a lot of web development for data entry work I thought it would be a good idea to come up with a tooltip function that would work easily with a form, let me leave little helpful notes for the user, and one where I could control how long the tooltip would remain visible on the screen so longer messages could be left.

Note: In the below code I am using the FindPosition function to find the position of an object. That function can be found in the Finding the Position of an object article on this site.

To use the tool tip simply call it from the input tag of your form when focus is set to it

Example:

<form>
<input value="click here" onfocus="tooltips(this,'Display a tool tip.');" type="text">
<input value="tab to here" onfocus="tooltips(this,'Display a longer tooltip for 30 seconds. ',30);" type="text">
</form>

Function:

 //*****
//***** Function to display a tool tip.
//***** @param obj - Object to display the tool tip for
//***** @param msg - Message to display
//***** @param displayseconds - *Optional* Number of seconds to display the tool tip
//***** @return void
//*****
var HideTipTimer = 0;
function tooltips(obj,msg,displayseconds) {

 // If not passed in set the default value for the optional displayseconds parameter
 displayseconds = (typeof(displayseconds)=="undefined") ? 10 : displayseconds;

 // Figure out where the input field object is on the screen by adding
 // up all the offsets for all the containing parent objects
 var obj_pos = FindPosition(obj);
 var tip_left = obj_pos[0];
 var tip_top = obj_pos[1];

 // Add obj height to top position so tip box DIV will show up underneath "obj"
 tip_top += obj.offsetHeight;

 // Create DIV tag object through DOM to hold the "tip" message (if it does not already exist)
 if (document.getElementById("tip") == null) {
  tipdiv = document.createElement("div");
  document.body.appendChild(tipdiv);
  tipdiv.setAttribute("id", "tip");
  // Allow a click on the "tip" div to hide the message.
  tipdiv.onclick = function (aEvent){this.style.display=”none”;};
 } else {
  // Div Tag allready esists, clear out old timer and get reference to it
  clearTimeout(HideTipTimer);
  tipdiv = document.getElementById("tip");
  tipdiv.style.display="none"; // Hide any old message
  tipdiv.innerHTML = "";
 }

 // Position tip box DIV
 tipdiv.style.zIndex = "500";
 tipdiv.style.position = "absolute";
 tipdiv.style.top = tip_top + "px";
 tipdiv.style.left = tip_left + "px";

 // Roughly figure how how wide to make tip box DIV based on the number
 // of characters in the message. If max width is exceeded then just use max width
 var iFontSize = 10;
 var iCharWidth = iFontSize / 2; // Assume characters are half as wide as they are tall
 var iMaxWidth = 250;
 var iNumChars = msg.length;
 var tip_width = (iNumChars * iCharWidth + 6 > iMaxWidth ) ? iMaxWidth : iNumChars * iCharWidth + 6;

 tipdiv.style.width = tip_width + "px";

 // Format the appearance of tip box DIV
 tipdiv.style.fontFamily = "Arial";
 tipdiv.style.fontSize = iFontSize + "px";
 tipdiv.style.backgroundColor = "lightyellow";
 tipdiv.style.border = "1px solid black";
 tipdiv.style.padding = "2px 2px 2px 4px";
 tipdiv.style.textAlign = "left";

 // If message is empty then set display type to hide tip box DIV
 (msg != "") ? display_type = "block" : display_type = "none";

 // Show/hide div and assign the message to the tip box
 tipdiv.style.display = display_type;
 tipdiv.innerHTML = msg;

 // If tip is being displayed then wait 10 seconds then hide the tip box DIV
 if (display_type == "block") {
  var cmd = 'document.getElementById("tip").style.display="none";';
  displayseconds = displayseconds * 1000;
  HideTipTimer = setTimeout(cmd,displayseconds);
 }

}
Email This Post Email This Post Print This Post Print This Post

Replacing History

Mon, Oct 15, 2007 – 4:41 am by Stan Slaughter

How to prevent a page from being placed into a web browsers history.

There are a lot of times when you want to disable a browsers “Back” button or delete items from a browsers history list.

Unfortunately there is no function that lets you delete items from history, but you can use the location.replace method to prevent the page from ever showing up in history to begin with.

location.replace(URL) - …loads the specified URL over the current history entry. After calling the replace method, the user cannot navigate to the previous URL by using browser’s Back button

Link: http://docs.sun.com/source/816-6408-10/location.htm#1194240

Example 1:

<script language="JavaScript">
  function ClickMe() {
    location.replace('http://www.yahoo.com');
  }
</script>

If the function ClickMe() was called in response to the user clicking on a button or hyper link then they would be taken to the www.yahoo.com web page AND the page they just left would *not* be in the history list. If they tried to use the Back button to return they would not return to it, but to the previous one.

Example 2:

<script language="JavaScript">
    location.replace('http://www.yahoo.com');
</script>

If the above script was placed between the <head> and </head> tags then the user would automatically be taken to the www.yahoo.com web page without ever having the current page displayed and without having it ever entered into the history list (useful when used on a page which does server side inserts to a database in response to input from a form - it prevents the user from hitting the “Back” button and accidently inserting duplicates)

Email This Post Email This Post Print This Post Print This Post

AutoComplete

Wed, Oct 10, 2007 – 11:54 am by Stan Slaughter

Introduction

Treat a forms input textbox like a drop down menu or like a standard text box with built in auto complete features!

AutoComplete Demo

This is a JavaScript function which has been designed to be easy to incorporate into existing online forms. It acts as an HTML control that integrates AutoComplete into the standard textbox. Adding a few lines of code allows you to turn any standard textbox into a user friendly feature which can function as an input textbox or as a drop down select menue.

How it works

Whenever the user types anything in the textbox, the onkeyup event is fired, and the script calls a function. The current text in the textbox is then compared with an array that contains the list of allowed values.

Additionally the user can click on the convenient drop down menu button at any tme to treat the textbox like any traditional form select menu.

For further information please check out the working demo by clicking on the link below

AutoComplete Demo