DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Pull Down Menu Next / Back Functionality

10.07.2005
| 719 views |
  • submit to reddit
        
function selectNextBack(name,direction) {
   var sel = (document.getElementById ? document.getElementById(name) : document.all[name]);
   if(sel == null) { return false; }
   var ops = sel.options.length;
   var num = sel.selectedIndex;
   if(ops > 0){
     if(direction == "next"){
	if (ops-num == 1){
	  sel.selectedIndex = 0;
	} else {
	  sel.selectedIndex = num+1;  
	}
      }else{
	if (num == 0){
	  sel.selectedIndex = ops-1;
	} else {
	  sel.selectedIndex = num-1;  
	}
      }
   }
}


EXAMPLE

<a href="javascript:void(0);" onclick="selectNextBack('itemid','back');">Back</a>
<select id="itemID" name="itemID">
	<option value=""></option>
	<option value="25">Item 1</option>
	<option value="76">Item 2</option>
	<option value="33" selected>Item 3</option>
	<option value="48">Item 4</option>
</select> 
<a href="javascript:void(0);" onclick="selectNextBack('itemid','next');">Next</a>