/    Sign up×
Community /Pin to ProfileBookmark

javascript search engine form

I am trying to create a pull-down-search-engine-menu. It works fine when I use the standard submit button; however, I want to use an image button instead. Can somebody take a look and see where I’m going wrong? Thanks in advanced for your help.

[CODE]<script language=”javascript”>
function getit(form){
engine=document.search.engine.options
[document.search.engine.selectedIndex].value;
if (engine == “google”) engine = “http://www.google.com/search?hl=en&q=”;
if (engine == “excite”) engine = “http://www.excite.com/search.gw?trace=1&search=”;
if (engine == “msn”) engine = “http://search.msn.com/results.aspx?q=movies”;
if (engine == “aolnetfind”) engine = “http://netfind.aol.com/search.gw?c=web&lk=netfind&src=1&search=”;
if (engine == “yahoo”) engine = “http://search.yahoo.com/bin/search?p=”;
if (engine == “lycos”) engine = “http://www.lycos.com/cgi-bin/pursuit?matchmode=and&cat=lycos&x=232&y=111&query=”;
if (engine == “hotbot”) engine = “http://www.search.hotbot.com/?SW=web&SM=MC&DC=10&DE=2&act.search.x=115&act.search.y=167&MT=”;
if (engine == “looksmart”) engine = “http://www.looksmart.com/r?look=mp&search=1&key=”;
keywords = convert(document.search.keywords.value);
location= engine +keywords
}

function convert(input) {
var output = “”;
for (var i = 0; i < input.length; ++i) {
var temp = input.charAt(i); if (temp == ” “) temp = “+”;
output += temp;
}
return output;
}
// –>
</script>

<form method=post name=search>
<span id=”search”>
Search:
<select name=”engine”>
<option value=”google”>Google
<option value=”excite”>Excite
<option value=”msn”>MSN
<option value=”aolnetfind”>AOL Netfind
<option value=”yahoo”>Yahoo
<option value=”lycos”>Lycos
<option value=”hotbot”>Hot Bot
<option value=”looksmart”>Look Smart
</select>

<input type=text size=35 name=keywords>
<input type=”image” src=”images/go.jpg” value=Search onclick=getit(this.form)>&nbsp;
<input type=”image” src=”images/reset.jpg” value=”Reset” alt=”Reset”>
</form>
[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisApr 24.2007 — The action of the input type="image" is to submit the form along with the coordinates of the mouse when the click occurs. Move the function call to the form tag:
&lt;form method=post name=search[color=red] onsubmit="getit(this);return false"[/color]&gt;
×

Success!

Help @cbeshears spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...