Solved

Radio button multisearch form

Posted on 1997-04-04
1
290 Views
Last Modified: 2008-03-03
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
Comment
Question by:owen
1 Comment
 
LVL 1

Accepted Solution

by:
moorep earned 50 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now