Welcome to WebmasterWorld Guest from 54.163.25.166

Forum Moderators: open

Message Too Old, No Replies

Javascript Hide/Show Div inside PHP Tag

mysql, php, javascript, div, reload, show, hide

     
8:31 am on Jun 6, 2012 (gmt 0)

New User

joined:May 24, 2012
posts: 8
votes: 0


I am hiding/showing divs using Javascript. I have added php pagenitation to the page and when I browse through the pagenitation, it jumps back to the first div and not the currently viewed div. Any suggestions how to get the Javascript to work inside the php tags?
Herewith the coding:

JAVASCRIPT INSIDE HEADER:
//show div and hide another
function showHide(d)
{
var onediv = document.getElementById(d);
var divs=['content1','content2','content3','content4','content5'];
for (var j=0;ji<divs.length;j++)
{
if (onediv != document.getElementById(divs[j]))
{
document.getElementById(divs[j]).style.display='none';
}
}
onediv.style.display = 'block';
}

NAVIGATION:
<!--navigation menu-->
<div class="menu2">
<a href="javascript:showHide('content1');">1</a>
<a href="javascript:showHide('content2');">2</a>
<a href="javascript:showHide('content3');">3</a>
<a href="javascript:showHide('content5');">5</a>
</div>
<!--end navigation menu-->

THE ACTUAL DIV:
<div class="topcontent" id="content5" style="display:none">

AND PAGINATION PHP:
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage' 'javascript:showHide('content5');'><</a> ";

</div>

I cannot get the Javascript to work inside the PHP tag
Please help
5:38 pm on June 6, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


Ooops, already answered here [webmasterworld.com]