bindiya Posted March 30, 2011 Share Posted March 30, 2011 I have a div which shows and hide when clicking on More and Less button. I have a pagination code in php written in this div.So when i click next button the next page come but the div will be close.How can i make this div opened when i go to the next page. <script type="text/javascript"> function toggle_fulltxt(id) { var v = document.getElementById('fulltxt'+id).style.display; var morelnk; var lesslnk; if (v=='none') { v='inline'; morelnk='none'; lesslnk='block'; } else { v='none'; morelnk='inline'; lesslnk='none'; } document.getElementById('fulltxt'+id).style.display = v; document.getElementById('fulltxtlnk'+id).style.display = morelnk; document.getElementById('lesstxtlnk'+id).style.display = lesslnk; return false; } </script> <script> function divs_style(){ document.getElementById('fulltxt001').style.display="inline"; } </script> <div id="fulltxtlnk001" style="display:inline">... <a href="" onClick="return toggle_fulltxt('001')" onMouseOver="window.status='Show full description'; return true;" onMouseOut="window.status=''; return true"><span class="style28">LISTS OF HOTELS</span> ></a></div> <div id="fulltxt001" style="display:none"> <?php //Next page: $next_page = $page + 1; if($next_page <= $total_pages) { echo('<a [color=red]onclick="divs_style();"[/color] href='.$pagename.'?limit='.$limit.'&page='.$next_page.'&emir='.$emi.' ><b>Next</b></a> > >'); } ?></p> </div><div id="lesstxtlnk001" style="display:none"><a href="" onClick="return toggle_fulltxt('001')" onMouseOver="window.status='Hide full description'; return true;" onMouseOut="window.status=''; return true">< Less</a></div> Quote Link to comment https://forums.phpfreaks.com/topic/232147-changing-div-style-property-onclick/ Share on other sites More sharing options...
trq Posted March 30, 2011 Share Posted March 30, 2011 You should seriously considering using a framework such as jQuery. Not only does it provide mechanism to separate your JavaScript from your markup but tasks like this become one liners. Quote Link to comment https://forums.phpfreaks.com/topic/232147-changing-div-style-property-onclick/#findComment-1194211 Share on other sites More sharing options...
Adam Posted March 30, 2011 Share Posted March 30, 2011 If I understand you right, with or without jQuery, you'd need to preserve the DIV state(s) by passing a parameter(s) within the pagination links. As an example: <a href="pagination.php?page=2&show_more=1">Next</a> Then at the end of your <body>: <?php if (!empty($_GET['show_more']) && $_GET['show_more']) { ?> <script type="text/javascript"> document.getElementById('my_div').style.display = 'block'; </script> <?php } ?> That's just to demonstrate the logic a little, fitting it into your own code will require some work. I wouldn't use this method myself though as it relies upon JavaScript to show the contents - though I'm not certain I followed your explanation well. Quote Link to comment https://forums.phpfreaks.com/topic/232147-changing-div-style-property-onclick/#findComment-1194244 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.