Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form id="cse-search-box" action="http://google.com/cse">
- <input type="hidden" name="cx" value="partner-pub-2789521296837340:9402765321" />
- <input type="hidden" name="ie" value="UTF-8" />
- <input type="text" name="q" size="31" />
- <input type="submit" name="sa" value="Search" />
- <!-- This is the new button - the "random" ID allows it to be targeted separately. -->
- <input id="random" type="submit" name="random" value="Random" />
- </form>
- // With input selected, do this on click
- $( "input#random" ).on('click', function() {
- // The array of possible search terms.
- var myArray = ['animals','dogs','cats', 'emu','fish','snakes', 'panda bears','meerkats','spiders','birds'];
- // Choose a term randomly
- var rand = myArray[Math.floor(Math.random() * myArray.length)];
- // Write them term in the search box and then submit the search
- var input = $("input[name='q']");
- input.val(input.val() + ' ' + rand);
- $( "form#cse-search-box" ).submit();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement