Solved

One form input box, two buttons.

Posted on 2002-04-02
7
220 Views
Last Modified: 2010-04-09
Here's my problem. I'm looking to have one text box to enter my search terms, but I want two different buttons to click to submit to different sites. For example, one time I want to search Google, the other time I want to search, say, Teoma. Regardless of the exact code needed for each particular search engine, how can I have two different buttons but one text box?

Here is what I have now:

<INPUT TYPE=text name=q size=40 maxlength=255 value="">
<INPUT type=submit name=gs VALUE="Google Search">
<INPUT type=hidden>

I can add and rename another button, but that won't change where the search is going to.
0
Comment
Question by:Decimal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 18

Expert Comment

by:bruno
ID: 6914487
i assume you have your form action set to the google search page.  

you can do this using javascript....


get rid of your form action..


<form method="post" name="myForm">

<input type="text" name="search" size="40" maxlength="255" value="" />
<input type="button" name="teoma" value="Google Search" onClick="googleSearch();" />
<input type="button" name="google" value="Google Search" onClick="teomaSearch();" />

</form>


and then put your actions into javascript....


i might do something like this for the google search...

<script>
function googleSearch();
{
window.location = "http://www.google.com/search?sourceid=navclient&q=" + myForm.search.value
}
</script>


I imagine the other search might work similar, but i'm not familiar with it.

I have not tested this, so please, if my script is wrong, someone correct me.


Good luck!

BRUNO


0
 
LVL 30

Expert Comment

by:third
ID: 6914822
"Regardless of the exact code needed for each particular search engine,
how can I have two different buttons but one text box?"

brunobear might be correct if that's the case but if they require form submission, here's a sample.

<script>
function search(srchengine){
  var actn = 'www.google.com/search?'; //default search engine. this should point to google search submission
  frm = document.myForm;
  var textToSearch = frm.search.value;
  if(srchengine=='teoma'){
    actn = 'www.teoma.com/search?'; //should point to teoma search submission
  }
  frm.action = actn + textToSearch;
  frm.submit();
}
</script>

<form method="post" name="myForm">
<input type="text" name="search" size="40" maxlength="255" value="">
<input type="button" name="teoma" value="Google Search" onClick="search('google');">
<input type="button" name="google" value="Teoma Search" onClick="search('teoma');">
</form>
0
 
LVL 23

Accepted Solution

by:
b1xml2 earned 200 total points
ID: 6915205
The simplest solution requires only pure HTML and in-line script.

<html>
<head>
<title>Search Submission</title>
</head>
<body>
<form method="get">
<input type="hidden" name="q">
<input type="hidden" name="t">
<input type="text" name="search" size="40" maxlength="255">
<input type="submit" value="Google Search" onclick="this.form.q.value = this.form.search.value; this.form.action = 'http://www.google.com/search';">
<input type="submit" value="Teoma Search" onclick="this.form.t.value = this.form.search.value;this.form.action = 'http://www.teoma.com/search.asp';">
</form>
</body>
</html>

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 23

Expert Comment

by:b1xml2
ID: 6915210
also, the code works since Google expects a q param and Teoma expects a t param.
0
 

Author Comment

by:Decimal
ID: 6921954
Thanks! Nice and simple.
0
 

Author Comment

by:Decimal
ID: 6921960
Oh hey, any way to get both of those buttons on one line without a table?
0
 

Author Comment

by:Decimal
ID: 6922022
Scratch that, my own mistake, it works fine on one line.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

632 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