Solved

Keeping a submenu open when loading a new webpage

Posted on 2008-06-23
2
203 Views
Last Modified: 2013-11-19
Hi!  

I have already found some answers to my question which help me a lot, but I need some further help if possible as I've not used any php before - not much javascript either!.  I have a css / javascript menu, I would like the relevant area of the sub menu to stay visible when the page re-loads (when the user clicks on a link within the sub menu).  You can see it working so far here http://www.thefeelgoodguide.co.uk/test  (am I allowed to put up links?)

I've found this answer by Ingwa... (pasted below) I have a php enabled server - but I just need to know what to do with this code - where to put it and if I need to edit it etc.  Or do I have any other options?

Thank you in advance!!
Emma

Answer...
:Another simpler method could be to use a session variable on the server which stores a value.  This remains "in state" while the users browser and connection to the server remain active.  It's also non-dependent on javascript, which ensures that even if the users javascript is disabled, as long as the form can post to php then the code will work.  The connection is only terminated after x number of seconds, which is usually set in the php.ini.  To set a session do this:

<?php session_start();

$_SESSION['myvar'] = $_POST['dropdownfield'];  // Selected test1
?>

<select name="'dropdownfield'" id="'dropdownfield'">
  <option value="test1" <?php if($_SESSION['myvar'] == "test1"){ echo 'selected="selected";} ?>">test1</option>
  <option value="test2" <?php if($_SESSION['myvar'] == "test2"){ echo 'selected="selected";} ?>>test2</option>
  <option value="test3" <?php if($_SESSION['myvar'] == "test3"){ echo 'selected="selected";} ?>>test3</option>
  <option value="test4" <?php if($_SESSION['myvar'] == "test4"){ echo 'selected="selected";} ?>>test4</option>

</select>

Hope this helps."



0
Comment
Question by:EmmaJW
2 Comments
 
LVL 18

Expert Comment

by:ingwa
ID: 21847698
Hi Emma,

The select is a form element.  If you need to add or delete from it (or change the values), it would be edited like a normal select (drop down list).  I would bind it in <form> tags and have the action point the page that you need the navigation open on.  E.g we are on index.html, have it point to nav.php, a page where you keep all your main navigation.  Put a go button on the form too so that it gets submitted.  Then a user selects what page they want and presses go, which submits to the php page, sets the session value and redraws the select, with the right sub nav selected.

0
 

Accepted Solution

by:
EmmaJW earned 0 total points
ID: 21847827
Hi Ingwa

Thanks for your help.  I didn't even notice the words "dropdownfield" in that code! Tch!  Unfortunately that's not what I need at all!  Sorry about that.  I just need my existing menu (not a drop down field with a go button) to remain open or to re-open in the right place when the page is reloaded.  Do you know if there's a way to do that?

Many thanks, and sorry for the confusion!
Emma
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now