By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,963 Members | 1,815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,963 IT Pros & Developers. It's quick & easy.

Adjust JavaScript for radio buttons replaced with dropdown select

100+
P: 229
Hi, I want to replace the input type="radio" with a dropdown <select>. I wonder if anyone could tell me how to adjust the javascript. I have tried replacing "checked" with "select" but it didnt work.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  5. <title>Name</title><script src="/js/validatesearch.js" type="text/javascript"></script>
  6. </head>
  7.  
  8. <body>
  9. <script type="text/javascript" language="JavaScript">
  10. <!-- Copyright 2003 Bontrager Connection, LLC
  11. // See article "Changing Form Action URLs On-The-Fly" linked 
  12. // from URL /library/archives 
  13. // for more information about how to use this code.
  14. function ActionDeterminator()
  15. {
  16. if(document.myform.reason[0].checked == true) {
  17. document.myform.action = '/search.asp';
  18. }
  19. if(document.myform.reason[1].checked == true) {
  20. document.myform.action = '/businesssearch.asp';
  21. }
  22. if(document.myform.reason[2].checked == true) {
  23. document.myform.action = 'artschoolsearch.asp';
  24. }
  25. return true;
  26. }
  27. // -->
  28. </script>
  29.  
  30. <form name="myform" method="post" action="search.asp" onsubmit="return validate_form(this)">
  31.  
  32. <input type="text" size="12" name="SearchWord" style="border: 0px solid #000; padding: 0px; background-color: #c0c0c0; margin-left: 0px; margin-right: 0px; vertical-align: middle;">
  33. <input onClick="return ActionDeterminator();" value="search" type="submit" style="border: 0px solid #000; padding: 1px 2px; background-color: #808080;margin-left: 1px;  vertical-align: middle; font-size: 10px; font-family: Verdana;" >
  34.  
  35.  
  36. <input type="radio" checked name="reason">art
  37. <input type="radio" name="reason">business
  38. <input type="radio" name="reason">tips
  39.  
  40.  
  41. </form>
  42. </body>
  43.  
  44. </html>
so swap the select for something like this.


Expand|Select|Wrap|Line Numbers
  1. <select>
  2. <option selected>please select</option>
  3. <OPTION>----------------------------------</Option>
  4. <option>art</option>
  5. <option>business</option>
  6. <option>tips</option>
  7. </select>

Any help would be great.
Thanks
Richard
Aug 14 '08 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
Add values to the options set as the URL to set the action to, then change ActionDeterminator to something like:
Expand|Select|Wrap|Line Numbers
  1. function ActionDeterminator()
  2. {
  3.     var val = document.myform.reason.value;
  4.     if (val != "") {
  5.         document.myform.action = val;
  6.     }
  7.     return true;
  8. }
PS. changed thread title to give it a better description.
Aug 14 '08 #2

100+
P: 229
thanks a lot
richard
Aug 14 '08 #3

acoder
Expert Mod 15k+
P: 16,027
You're welcome. Glad it's working :)
Aug 14 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.