• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 401
  • Last Modified:

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

0
Gary Samuels
Asked:
Gary Samuels
  • 4
  • 4
1 Solution
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now