Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error I Can't Figure Out, Help!

    I'm sure that one of you will be able to glance at this and tell me what's wrong with it.

    I have a search engine javascript that worked just fine when I had it in a dropdown box. When I switched it to radio buttons, it quit working, and nothing I have tried has fixed it. Here's the working script:

    <head>
    <script type="text/javascript">
    function dosearch() {
    var sf=document.searchform;
    var submitto = sf.sengines.options[sf.sengines.selectedIndex].value + escape(sf.searchterms.value);
    window.location.href = submitto;
    return false;
    }
    </script>
    </head>

    <body>
    <form name="searchform" onSubmit="return dosearch();">

    <select name="sengines">
    <option value="http://www.google.com/search?q=" selected>Google</option>
    <option value="http://www.altavista.com/web/results?q=">Alta Vista</option>
    <option value="http://www.dogpile.com/info.dogpl/search/web/">Dogpile</option>
    <option value="http://search.yahoo.com/search?p=">Yahoo!</option>
    <option value="http://www.bing.com/search?q=">Bing</option>
    </select>

    <input type="text" name="searchterms">
    <input type="submit" name="SearchSubmit" value="Search">
    </form>
    </body>


    And here's what I want the form to look like:

    <input type="radio" name="sengines" value="http://www.google.com/search?q=">
    <img src="google_icon.gif">
    <input type="radio" name="sengines" value="http://www.altavista.com/web/results?q=">
    <img src="altavista_icon.gif">
    <input type="radio" name="sengines" value="http://www.dogpile.com/info.dogpl/search/web/">
    <img src="dogpile_icon.gif">
    <input type="radio" name="sengines" value="http://search.yahoo.com/search?p=">
    <img src="yahoo_icon.gif">
    <input type="radio" name="sengines" value="http://www.bing.com/search?q=">
    <img src="bing_icon.gif">

    Unfortunately, changing the form to radio buttons seems to break. I know it's something easy I'm missing...Help!

  • #2
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    Radio button groups don't have a selectedIndex property, you must scan for a selected button. This may work:
    Code:
    function dosearch() 
    {
     var sf = document.forms.searchform, sfe = sf.engines;
    
     for( var i = 0, len = sfe.length; i < len && !sfe[ i ].checked; i++ )
     ;
    
     if ( i != len )
     {
      var submitto = sfe[ i ].value +  escape(sf.searchterms.value);
    
      window.location.href = submitto;
     }
    
     return false; 
    }

  • #3
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Indeed it does, with the change from "engines" to "sengines." Thank you so much!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •