Link to home
Start Free TrialLog in
Avatar of Decimal
Decimal

asked on

One form input box, two buttons.

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.
Avatar of bruno
bruno
Flag of United States of America image

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


"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>
ASKER CERTIFIED SOLUTION
Avatar of b1xml2
b1xml2
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
also, the code works since Google expects a q param and Teoma expects a t param.
Avatar of Decimal
Decimal

ASKER

Thanks! Nice and simple.
Avatar of Decimal

ASKER

Oh hey, any way to get both of those buttons on one line without a table?
Avatar of Decimal

ASKER

Scratch that, my own mistake, it works fine on one line.