Jump Menu selection

I know very little Javascript so I used dreamweaver to created a small dropdown menu. It works but after you are directed to your selected page the menu defaults back to the first selection of the menu. I would like the menu to refelect the current page or in other words simply stay on the users selection after the redirect. This will help the user know which page he/she is on.

<script type="text/javascript">
<!--
function MM_jumpMenuGo(objId,targ,restore){ //v9.0
  var selObj = null;  with (document) { 
  if (getElementById) selObj = getElementById(objId);
  if (selObj) eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0; }
}
//-->
</script>
 
 
 
 
<form name="form" id="form">
  <select name="jumpMenu" id="jumpMenu">
    <option value="#">item1</option>
    <option value="#">item2</option>
    <option value="#">item3</option>
  </select>
  <input type="button" name="go_button" id= "go_button" value="Go" onclick="MM_jumpMenuGo('jumpMenu','parent',0)" />
</form>

Open in new window

Gary SamuelsPlant ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

azcheCommented:
Hi, please give us more info about how you are using it..
 you are calling it form different windows, right?
and the options value..  isn't #?
another thing.. check out the line 7:
if (restore) selObj.selectedIndex=0;
you can remove this and the last, (both in the script and call)
0
Gary SamuelsPlant ManagerAuthor Commented:
I removed the last line and the last parameter in the both the script and form and it made no difference.
You can see the work in progress at:
www.iccommerce.com/page/D3/CTGY/Detroit_Lions_Fan_Apparel

The idea is to switch between different urls within the same window . The real code looks something like:
<script type="text/javascript">
<!--
function MM_jumpMenuGo(objId,targ,restore){ //v9.0
  var selObj = null;  with (document) { 
  if (getElementById) selObj = getElementById(objId);
  if (selObj) eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0; }
}
//-->
</script>
 
 
<form name="form" id="form">
<mvt:item name="toolkit" param="childof|parentfound|g.Category_Code" />
  <select name="jumpMenu" id="jumpMenu">
    <option value="/page/D3/CTGY/Detroit_Lions">ALL</option>
    <option value="/page/D3/CTGY/Detroit_Lions_Fan_Apparel">Fan Apparel</option>
    <option value="/page/D3/CTGY/Detroit_Lions_Wall_Accessories">Wall Accesories</option>
    <!-- and so on -->
  </select>
  <input type="button" name="go_button" id= "go_button" value="Apply Filter" onclick="MM_jumpMenuGo('jumpMenu','parent',0)" />
 
</form>

Open in new window

0
Gary SamuelsPlant ManagerAuthor Commented:
Again the idea is that if you click on 'Fan Apparel' it takes you to the Fan Apparel page, on this page the drop-down list should show 'Fan Apparel' not 'All"

BTW I can't hard code the drop down for each page. Whatever the selectedIndex was to bring you to the your current page that index should still be the selected index.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

azcheCommented:
the form is inside the html? .. you can add selected="true" to the <option> in each page
0
azcheCommented:
ok.. what i suggest is to use a cookie to set and read the value for example

function createCookie(name,value) {
      if (days) {
            var date = new Date();
            date.setTime(date.getTime()+(86400000)); // 1 day
            var expires = "; expires="+date.toGMTString();
      }
      else var expires = "";
      document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
      var nameEQ = name + "=";
      var ca = document.cookie.split(';');
      for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
      }
      return null;
}

change the jumpMenu function to set the cookie

function MM_jumpMenuGo(objId,targ,restore){ //v9.0
  var selObj = null;  with (document) {
  if (getElementById) selObj = getElementById(objId);
  if (selObj){
     createCookie('menu', selObj.selectedIndex);
     eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  }
  if (restore) selObj.selectedIndex=0; }
}


so in the onload you can call another function  to set selectedIndex acording to the cookie value..

function setIndex(){
   var index = readCookie('menu');
   getElementById('jumpMenu').selectedIndex = index;
}

i dont test it .. i suposse it may work
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gary SamuelsPlant ManagerAuthor Commented:
nope, can't do that, the pages are dynamic. the same code snippet is added to every page. I can't hard code for an individual page.
0
azcheCommented:
so add it to every page.. you can modify setIndex() to work if jumpMenu exists
0
Gary SamuelsPlant ManagerAuthor Commented:
I did not try cookie idea because your previous idea of adding the selected=true gave me the idea of wrapping the option statements in a condition. I used an if statement to check if the page was equal to the page and if so add the selected=true value and it worked.
Thanks for the help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.