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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Onclick to Show Element on next page

Status
Not open for further replies.

083

Programmer
Joined
Aug 3, 2005
Messages
2
Location
ZA
I want my link to open the selected element on the next page but because the page with text elements hides all when it opens it cancels out the request in the link.

About1.html:
<a href="about2.html" onClick="showElement('id1');"

About2.html:
<SCRIPT LANGUAGE="JavaScript">
function showElement(element)
{
HideAll();
var target = document.getElementById(element);
target.style.display='block';
}
function hideElement (element)
{
var target = document.getElementById(element);
target.style.display='none';
}
function HideAll()
{
hideElement('id1');
hideElement('id2');
hideElement('id3');
hideElement('id4');
hideElement('id5');
}
</SCRIPT>
<body ONLOAD="HideAll()">

Please help!
 
Don't hide all onload, instead call a function that reads the url data and shows the relevant elements.

remember you can add a style to the div tag with visibility:hidden, so they all default to hidden when page loads!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Hi 1DMF

Could you post me the function that calls the url data. I am really bad at javascript. I learn from copy pasting! I removed the hideall function and inserted the visibility style but now nothing displays.
Did i miss something?
Thanks!
 
No the idea is that they are all hidden, via the visibility set to hidden.

Then onload call a function that reads the URL or use a cookie, that reads what ID should be made visible and sets the style to visible.

onload="showit();"

Code:
function showit()
{

//You need to write the code here to read either the cookie set from previous page or read the URL data and then set an array = ids for making visible. set length of array then loop over a bit like this.

for(x=0; x<=number_of_ids; x++){

   document.getElementById(id[x]).style.visibility = 'visible';

}

}

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top