Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript to control div.

Status
Not open for further replies.

newbie14

Technical User
Feb 14, 2009
81
MY
Dear All,
I have 3 different types of div. One div is on my left and I named as left as below. Then I want to have 2 different div on my right. The problem is that for my right div at anytime only 1 should be visible the other should be not visible. On page load only my id="menu1" should be visible. So inside this div I have some images. The problem now is that I want a javascript when when I click on the image my current div id="menu1" should be invisible and at the same location my second div id="menu2" should be visible. I have put both my div here. Any help on this please ? Thank you.
<div id="left">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Prime Details</div></td>
</tr>
<tr>
<td>Prime Details2</div></td>
</tr>
</table>
</div>

<div id="menu1" style="position: relative;left: 600px;">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="images/b1.jpg" width="134" height="39" border="0" NAME="but1" />
</td>
</tr>
</table>
</div>
<div id="menu2" style="position: relative;left: 600px;">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="images/b2.jpg" width="134" height="39" border="0" NAME="but2" />
</td>
</tr>
</table>
</div>
 
Hi

JavaScript:
function change(what)
{
  if (!what || what.name=='but1') {
    document.getElementById('menu1').style.display='none'
    document.getElementById('menu2').style.display='block'
  } else {
    document.getElementById('menu1').style.display='block'
    document.getElementById('menu2').style.display='none'
  }
}
window.onload=change
HTML:
[small]<div id="menu1" style="position: relative;left: 600px;">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>[/small]<img alt="images/b1.jpg" width="134" height="39" border="0" NAME="but1" [red]onclick="change(this)"[/red]/>
[small]</td>
</tr>
</table>
</div>
<div id="menu2" style="position: relative;left: 600px;">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>[/small]<img alt="images/b2.jpg" width="134" height="39" border="0" NAME="but2" [red]onclick="change(this)"[/red]/>
[small]</td>
</tr>
</table>
</div>[/small]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top