Redirect with a Dropdown Menu in JavaScript


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

This simple scripts show a possibility to call a JavaScript function that retrieves a variable passed from drop down box as a parameter and then the JavaScript redirects the browser to the variable that was passed to it.


Copy this code and paste it in your HTML
  1. <script type="text/javascript">
  2. function do_redirect(site){
  3. window.location.href = site;
  4. }
  5. </script>
  6.  
  7. <select onchange="do_redirect(this.value)">
  8. <option value="#">What site would you like to see?</option>
  9. <option value="http://www.google.com">Google</option>
  10. <option value="http://www.yahoo.com">Yahoo</option>
  11. <option value="http://www.apphp.com">ApPHP</option>
  12. </select>

URL: http://www.apphp.com/index.php?snippet=javascript-redirect-with-dropdown-menu

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.