Show/hide button: put result into POST variable

Tag: show-hide Author: Up_sky Date: 2012-12-19

I have a long list of links in my website's menu. I show the first three links per default, and I have a "Show/hide" button for the rest of the links.

I would like to be able to change the default value (show or hide) according to the visitor's preference.

--> So the default value is "hide" to start with. If the visitor clicks "show" and then clicks a link, I want the next page to be "show" per default. If he then clicks hide, default is "hide".

Below is my menu. 1-2-3 are always shown, 4-5-6 are shown or hidden.

<ul>
  <li><a href="test.php">1</a></li>
  <li>2</li>
  <li>3</li>

  <div class="liste-cachee">
    <div class="quotecontent">
     <div style="display: none;">
      <li>4</li>
      <li>5</li>
      <li>6</li>
     </div>
    </div>
  </div>

 <input type="button" value="Plus / Moins" onclick="if (
 this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != 'block') { 
 sendMenuDisplay('block'); 
 this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'block'; 
 } else { 
 sendMenuDisplay('none'); 
 this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none';  }" />

</ul>

My question is: How can I save what the visitor choses (show or hide), put it in a $_POST variable and use it as the default value on the next page?

Thanks for your time and help

Clio

What is your question?
Sorry I realise that is not clear. My question is: How can I save what the visitor chose (show or hide), put in a $_POST variable and use it as the default value on the next page?

Other Answer1

You could POST or PUT the value and put in a cookie or a session attribute for use in subsequent pages. You could also POST or PUT the value using ajax and put the value in a cookie or session attribute for later use. You could also store the value in a database and use across user-sessions.

comments:

Those are all good solution, but I don't know how to actually save the value to store it into a POST, database or other. Since show/hide is determined without reloading the page, how can I extract the value? In the "onclick" code, how can I say "onclick show/hide and store that value somewhere"?