random selector


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. window.onload = function(){
  2. document.getElementById("randomButton").addEventListener('click', selectRandomOption, false);
  3. }
  4.  
  5. function selectRandomOption() {
  6. var box = document.getElementById('s_box');
  7. box.selectedIndex=box.length-1;
  8. box.selectedIndex=((Math.random()*box.length)-1);
  9. };

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.