Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. <form id="cse-search-box" action="http://google.com/cse">
  2. <input type="hidden" name="cx" value="partner-pub-2789521296837340:9402765321" />
  3. <input type="hidden" name="ie" value="UTF-8" />
  4. <input type="text" name="q" size="31" />
  5. <input type="submit" name="sa" value="Search" />
  6. <!-- This is the new button - the "random" ID allows it to be targeted separately. -->
  7. <input id="random" type="submit" name="random" value="Random" />
  8. </form>
  9.  
  10. // With input selected, do this on click
  11. $( "input#random" ).on('click', function() {
  12.  
  13. // The array of possible search terms.
  14. var myArray = ['animals','dogs','cats', 'emu','fish','snakes', 'panda bears','meerkats','spiders','birds'];
  15.  
  16. // Choose a term randomly
  17. var rand = myArray[Math.floor(Math.random() * myArray.length)];
  18.  
  19. // Write them term in the search box and then submit the search
  20. var input = $("input[name='q']");
  21. input.val(input.val() + ' ' + rand);
  22.  
  23. $( "form#cse-search-box" ).submit();
  24. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement