Most of the times it is dull to have that long scrolling HTML pages with anchor tags to display many products, all in one page. Java Script can be used to display all the products or information in one row depending upon the links clicked. You would understand if your see the example below.


First the details of individual products are enclosed in <span> tag and specifiying a unique id to the span tag. Like <span id=”1″></span>. All the span tags are included with style display equal to none. i.e., <span id=”1″ style=”display:none;”></span>. Then seperate links are created in the top horizontally or vertically for all the products. When each links are clicked a java script function is called to display the details corresponding to that particular link and to hide the previous text or details. This is achieved by dynamically altering the display value to ‘null’ for the active product details and display value to ‘none’ for all other product details.

The code snippet is given below. Though the code looks very lengthy it is very simple to understand.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
 <html xmlns="">
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>Same Page Navigation using Java Script</title>

<script language="JavaScript" type="text/javascript">
 function show_details(Menu_Clicked, menu1, menu2, menu3)
 // Function to display the details of individual products and hide the previous text.
 if ( == "none")
 { = ""; = "none"; = "none"; = "none";



 <table width="400" border="0" cellspacing="0" cellpadding="4">
 <td align="left" valign="top">
 <a href="javascript:show_details(display1, display2, display3, display0)" onMouseOver="window.status='';return true">Product1</a> &nbsp;&nbsp;
 <a href="javascript:show_details(display2, display1, display3, display0)" onMouseOver="window.status='';return true" onclick="window.status='';return true">Product 2</a> &nbsp;&nbsp;
 <a href="javascript:show_details(display3, display1, display2, display0)" onMouseOver="window.status='';return true">Product 3</a>
 <span id="display0" style="">Default Text about all the product in general</span>
 <span id="display1" style="display:none">Details of Product 1</span>
 <span id="display2" style="display:none">Details of Product 2</span>
 <span id="display3" style="display:none">Details of Product 3</span>


This code can also be used to create a simple photo gallery.