Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 334
  • Last Modified:

Radio button multisearch form

I was hoping that you could help me with a little javascript problem
that I have.
While surfing around the net I have come upon some multiple search
forms. They use one input field to access numerous search engines. The
most basic of these that I have seen is the one that I am trying to work
with.
Its code follows...

<head>
     <script language="JavaScript">
        var FirstForm;
           function StartSearch(){
             
document.forms[FirstForm+document.InputForm.SearchSelect.selectedIndex].elements[0].value=document.InputForm.SearchWords.value;
             
document.forms[FirstForm+document.InputForm.SearchSelect.selectedIndex].submit();
           }
     </script>
  </head>
  <body>
     <form Name="InputForm">
        Search For: <input name="SearchWords" type=text size=30>
        Search Engine: <select Name="SearchSelect">
           <option selected>Yahoo
           <option>Altavista
           <option>Excite
           <option>Lycos
        </select>
        <input type=button value="Search" onClick="StartSearch()">
     </form>

     <script
language="JavaScript">FirstForm=document.forms.length</script>

     <form action="http://search.yahoo.com/bin/search" method=get>
        <input type="hidden" size=35 name=p>
     </form>

     <form action="http://www.altavista.digital.com/cgi-bin/query"
method=get>
        <input type="hidden" name=q size=35 maxlength=200 value="">
        <input type="hidden" name=pg value=q>
        <input type="hidden" name="fmt" value=".">
        <input type="hidden" name=what value=web>
     </form>

     <form action="http://www.excite.com/search.gw" method=post>
        <input type="hidden" name="search" size=35>
        <input type="hidden" name="searchType" value="Keyword">
        <input type="hidden" name="category" value="default" checked>
        <input type="hidden" name="mode" value="relevance">
        <input type="hidden" name="showqbe" value="1">
        <input type="hidden" name="display" value="html3,hb">
     </form>

     <form
action="http://www.lycos.com/cgi-bin/nph-randurl/cgi-bin/largehostpursuit1.html">
        <input type=hidden size=35 name="query">
     </form>
  </body>

The above, as you see, only uses very limited javascript to get the job
done. For me this is fine and while this is okay I would like to be able
to use radio buttons to make the selection instead of the option box.
I am sure that this is possible but for me it has not been something I
have been able to do. Believe me, I have tried, but my limited
javascript knowledge is my downfall here.

The following is one of my atempts...

<HTML>
<head>
<SCRIPT language="JavaScript">
        var FirstForm;

        function StartSearch(form){
        for (Count = 0; Count < 4; Count++) {
                if (form.SearchSelect[Count].checked)
                        break;
                {
       
document.forms[FirstForm+document.form.SearchSelect.checked].elements[0].value=document.InputForm.SearchWords.value;
               
document.forms[FirstForm+document.form.SearchSelect.checked].submit();
                }
        }
}
</script>
</head>

<body>

<form Name="InputForm">
Search For: <input name="SearchWords" type=text size=30>
<input type=button value="Search" onClick="StartSearch(form)">
<br>
<br><br>
Search Engine:
<BR>
<INPUT TYPE="radio" NAME="SearchSelect" CHECKED onClick=0>Yahoo<BR>
<INPUT TYPE="radio" NAME="SearchSelect" onClick=0>Altavista<BR>
<INPUT TYPE="radio" NAME="SearchSelect" onClick=0>Excite<BR>
<INPUT TYPE="radio" NAME="SearchSelect" onClick=0>Lycos<BR>

</FORM>

<br></form>

    <script
language="JavaScript">FirstForm=document.forms.length</script>

    <form action="http://search.yahoo.com/bin/search" method=get>
       <input type="hidden" size=35 name=p>
    </form>

    <form action="http://www.altavista.digital.com/cgi-bin/query"
method=get>
       <input type="hidden" name=q size=35 maxlength=200 value="">
       <input type="hidden" name=pg value=q>
       <input type="hidden" name="fmt" value=".">
       <input type="hidden" name=what value=web>
    </form>

    <form action="http://www.excite.com/search.gw" method=post>
       <input type="hidden" name="search" size=35>
       <input type="hidden" name="searchType" value="Keyword">
       <input type="hidden" name="category" value="default" checked>
       <input type="hidden" name="mode" value="relevance">
       <input type="hidden" name="showqbe" value="1">
       <input type="hidden" name="display" value="html3,hb">
    </form>

    <form
action="http://www.lycos.com/cgi-bin/nph-randurl/cgi-bin/largehostpursuit1.html">
       <input type=hidden size=35 name="query">
    </form>

</BODY>

I don't know, was I on the right track with this?
I am sure that you see what I am trying to do here. Can you help me with
this? As I said, my javascript knowledge is very limited at this time,
so be as simplistic as possible in your solutions to my problem please!
If a "solution" to my problem can be given it would be greatly
appreciated.

Regards,

Owen.
0
owen
Asked:
owen
1 Solution
 
moorepCommented:
why not include the url as the value of the option (give the option buttons all the same names) and then concatenate the query  to this value (with appropriate parameters) in a JavaScript function. Use a <INPUT TYPE="button" onClick="MyFunc()">
instead of a submit button.
<SCRIPT etc>
function MyFunc() {
    document.location=SearchSelect.value+"bin/query?p="+MyQuery.value;
// end func
}
</SCRIPT>
<FORM etc>
<INPUT TYPE=text NAME="MyQuery">
<INPUT TYPE="radio" NAME="SearchSelect" VALUE="http://www.yahoo.com/">YAHOO
<INPUT TYPE="radio" etc.....
<INPUT TYPE=button VALUE="Search" onClick="MyFunc()">
</FORM>
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now