I have little work in hand and I a missing one concept in web development.I need to change the web contents dynamically.I want if users click Home or downloads on the navigation menu the contents should change without changing the URL.Study the code below ,run them on a browser and see where I am I missing.Once I am able to fix this one,I expect to use the concept for my other web related jobs.I am a beginner in web development haven't made one live website,someone told me the best way to learn is to start a small project.Thanks you in advance
<DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Displaying and hiding elements</title>
<style type="text/css">
div.menuTest{border-style:solid;border-width:thin;border-color:transparent;}
div.menuTest:hover{border-style:solid;border-width:thin;border-color:black;cursor:pointer;background-color:#009900;}
div.menuTest:Active{border-style:dotted;border-width:thin;border-color:black;cursor:pointer;background-color:#009900}
td.menuCell{width:25%;color:white;font-family:calibri,sans-serif;text-align:center;}
div#content{width:100%;height:100%;text-align:left;background-color:#009900;font-size:12px;font-family:verdana;overflow:auto;white-space:nowrap;}
div#contentArea{width:100%;height:100%;text-align:left;background-color:#009900}
div#contentHead{font-weight:bold;color:white;}
div#contentBody_Home{display:block;color:white}
div#contentBody_Downloads{display:none;color:white}
div#contentBody_Articles{display:none;color:white }
div#contentBody_Contacts{display:none;color:white}
hr {color:black;background-color:black;border:0px;height:1px;}
fieldset{height:25%;width:43%;background-color:#009900;border-color:black;border-style:solid;border-width:1px}
</style>
<script type="text/javascript">
function changeContent(page){
var header=document.getElementById('contentHead');
var pgHome=document.getElementById('contentBody_Home');
var pgArticles=document.getElementById('contentBody_articles');
var pgDownloads=document.getElementById('contentBody_Downloads');
var pgContact=document.getElementById('contentBody_Contact');
switch(page)
{
default:alert("This should not happen.....");
break;
case "Home": pgHome.style.display='block';
pgArticles.style.display='none';
pgDownloads.style.display='none';
pgContact.style.display='none';
header.innerHTML='Home';
break;
case "Articles": pgHome.style.display='none';
pgArticles.style.display='block';
pgDownloads.style.display='none';
pgContact.style.display='none';
header.innerHTML='Articles';
break;
case "Downloads": pgHome.style.display='none';
pgArticles.style.display='none';
pgContact.style.display='none';
pgDownloads.style.display='block';
header.innerHTML='Downloads';
break;
case "Contact": pgHome.style.display='none';
pgArticles.style.display='none';
pgDownloads.style.display='none';
pgContact.style.display='block';
header.innerHTML='Contact';
break;
}
}
</script>
</head>
<body bgcolor="grey">
<centre>
<!-- Horizontal menu goes here -->
<table style="min-width:45%;border-style:solid;border-width:thin;border-color:black;"cellspacing="5" padding="0";>
<tr style="width:100%;background-color:#00af00;">
<td class="menuCell" ><div class="menuTest" onclick="changeContent('Home');"><b>Home</b><div></td>
<td class="menuCell" ><div class="menuTest" onclick="changeContent('Articles');"><b>Articles</b></div></td>
<td class="menuCell" ><div class="menuTest" onclick="changeContent('Downloads');"> <b>Downloads</b></div></td>
<td class="menuCell" ><div class="menuTest" onclick="changeContent('Contact');"> <b>Contact</b></div></td>
</tr>
</table>
<br/>
<fieldset align="center" id="contentArea">
<div id="content">
<div id="contentHead">Home</div>
<hr/>
<div id="contentBody_Home">
<p>Welcome to our home page.Home contents goes here...</p>
</div>
<div id="contentBody_Contact">
<p>Welcome to our contact page.You can reach us via <br/>
Tel :097872647646<br/>
Po.Box 56<br/>
Mafinga.</p>
</div>
<div id="contentBody_Articles">
<p>Welcome to our articles page.Article contents goes here...</p>
</div>
<div id="contentBody_Downloads">
<p>Welcome to our downloads page.Download contents goes here...</p>
</div>
</div>
</fieldset>
</centre>
</body>
</html>

New Topic/Question
Reply


MultiQuote




|