Jump to content

changing div style property onclick


bindiya

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/232147-changing-div-style-property-onclick/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.