Last active
August 29, 2015 14:27
-
-
Save answerquest/6ba639a8fdb3bffb89e1 to your computer and use it in GitHub Desktop.
Cycle through a dropdown list : Previous/Next buttons to traverse through the options in a dropdown list. See working example: http://codepen.io/nikhilsheth/pen/pJmvEd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <meta charset="utf-8" /> | |
| </head> | |
| <body> | |
| <input type="button" value="previous" onClick="nextTiles(-1)"> | |
| <select id="overlaySelector" onChange="changeTiles()"> | |
| <option value="1" selected="selected">Option 1</option> | |
| <option value="2">Option 2</option> | |
| <option value="3">Option 3</option> | |
| </select> | |
| <input type="button" value="next" onClick="nextTiles(1)"> | |
| <script> | |
| function changeTiles() { | |
| //do whatever you're doing | |
| ; | |
| } | |
| function nextTiles(i) { | |
| var e = document.getElementById("overlaySelector"); | |
| e.selectedIndex +=i ; | |
| //loop-around from the top or bottom depending on increment/decrement | |
| if(e.selectedIndex == -1) { | |
| if(i>0) e.selectedIndex = 0; | |
| else e.selectedIndex = e.length - 1; | |
| } | |
| changeTiles(); //with the now updated selected option, | |
| //do whatever you were doing when the user manually chooses something in the dropdown | |
| } | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment