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.
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.
"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>
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
also, the code works since Google expects a q param and Teoma expects a t param.
ASKER
Thanks! Nice and simple.
ASKER
Oh hey, any way to get both of those buttons on one line without a table?
ASKER
Scratch that, my own mistake, it works fine on one line.
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