Home arrow JavaScript arrow Page 3 - ACP Tab Web Page
JAVASCRIPT

ACP Tab Web Page


A tab web page is a perfect candidate for the technology of Active Client Pages (ACP). It's a web page with buttons at the top. When you click a button, all the HTML content below the line of buttons changes. It is as if each button has a page hidden in it. ACP makes loading those pages go much more quickly.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
October 19, 2009
TABLE OF CONTENTS:
  1. · ACP Tab Web Page
  2. · ACP Feature
  3. · The Code
  4. · The Ajax Functions

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
ACP Tab Web Page - The Code
(Page 3 of 4 )

This is the web page code without the script for the Ajax functions.

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<script type="text/javascript">

tab1Page = "";

tab2Page = "";

tab3Page = "";


function showTabPage(butNo)

{

switch(butNo)

{

case '1':

document.getElementById('D1').innerHTML = tab1Page;

break;

case '2':

document.getElementById('D1').innerHTML = tab2Page;

break;

case '3':

document.getElementById('D1').innerHTML = tab3Page;

}

 

}

</script>

</head>

<body>

<button type="button" onclick="showTabPage('1')">Tab 1</button><button type="button" onclick="showTabPage('2')">Tab 2</button><button type="button" onclick="showTabPage('3')">Tab 3</button><br />

<div id="D1">

Page HTML Elements for Tab One.

</div>


<script type="text/javascript">

 

tab1Page = document.getElementById('D1').innerHTML;


</script>

</body>

</html>

The first three lines are XHTML requirements. You have a HEAD element, which has a JavaScript. The function of this JavaScript in the HEAD element is to display the page content of the tab button clicked. I will explain the details shortly.

The web page has the BODY element. This BODY element has the DIV element and another JavaScript. The content of the DIV element you see after the file has just been called is that of the first real page.

The JavaScript has the Ajax functions. However, the first statement in the script copies the content of the DIV element to the variable that holds the string of the first page. We shall learn more about this variable later.

The loading of the first file should be done in such a way that when the user clicks the tab for the first real page, after clicking the tab for the second or third real page, the content of the first real page should be available. You can say that this statement stores the content of the first real page.

The JavaScript in the Head Element

The JavaScript in the HEAD element begins with the following three lines:

tab1Page = "";

tab2Page = "";

tab3Page = "";

Each of these variables will hold the string content of a page. The first one holds the content for the first tab, the second one holds it for the second tab and the third holds it for the third tab. The string values for the content are assigned in the code. Next in this script, you have the following function:

function showTabPage(butNo)

{

switch(butNo)

{

case '1':

document.getElementById('D1').innerHTML = tab1Page;

break;

case '2':

document.getElementById('D1').innerHTML = tab2Page;

break;

case '3':

document.getElementById('D1').innerHTML = tab3Page;

}

 

}

When any tab is clicked, this is the function that is called. The function receives the button number of the tab clicked as an argument. In this example I used string instead of integer for the button number.

The function has a switch statement. If the button number is "1," the first case replaces the content of the DIV element with value of the tab1Page variable. The ID of the DIV element is "D1." If the button number is "2," the first case replaces the content of the DIV element with the value of the tab2Page variable. If the button number is "3," the first case replaces the content of the DIV element with the value of the tab3Page variable. This is how the page content is changed.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials