Adjust JavaScript for radio buttons replaced with dropdown select

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fran7
    New Member
    • Jul 2006
    • 229

    Adjust JavaScript for radio buttons replaced with dropdown select

    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.

    Code:
    <html>
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Name</title><script src="/js/validatesearch.js" type="text/javascript"></script>
    </head>
    
    <body>
    <script type="text/javascript" language="JavaScript">
    <!-- Copyright 2003 Bontrager Connection, LLC
    // See article "Changing Form Action URLs On-The-Fly" linked 
    // from URL /library/archives 
    // for more information about how to use this code.
    function ActionDeterminator()
    {
    if(document.myform.reason[0].checked == true) {
    document.myform.action = '/search.asp';
    }
    if(document.myform.reason[1].checked == true) {
    document.myform.action = '/businesssearch.asp';
    }
    if(document.myform.reason[2].checked == true) {
    document.myform.action = 'artschoolsearch.asp';
    }
    return true;
    }
    // -->
    </script>
    
    <form name="myform" method="post" action="search.asp" onsubmit="return validate_form(this)">
    
    <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;">
    <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;" >
    
    
    <input type="radio" checked name="reason">art
    <input type="radio" name="reason">business
    <input type="radio" name="reason">tips
    
    
    </form>
    </body>
    
    </html>
    so swap the select for something like this.


    Code:
    <select>
    <option selected>please select</option>
    <OPTION>----------------------------------</Option>
    <option>art</option>
    <option>business</option>
    <option>tips</option>
    </select>

    Any help would be great.
    Thanks
    Richard
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Add values to the options set as the URL to set the action to, then change ActionDetermina tor to something like:
    [CODE=javascript]function ActionDetermina tor()
    {
    var val = document.myform .reason.value;
    if (val != "") {
    document.myform .action = val;
    }
    return true;
    }[/CODE]PS. changed thread title to give it a better description.

    Comment

    • fran7
      New Member
      • Jul 2006
      • 229

      #3
      thanks a lot
      richard

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You're welcome. Glad it's working :)

        Comment

        Working...