Submitting form with image as button does not work

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
TGP
Forum Newbie
Posts: 6
Joined: Wed Jan 07, 2009 10:34 am

Submitting form with image as button does not work

Post by TGP »

In the head of my page:

<script type="text/JavaScript">
<!--
function Login(){
var done=0;
var keyword=document.enter_keyword.keyword.value;
//keyword=keyword.toLowerCase();
if (keyword=="r4ds") { window.location="http://www.google.co.uk"; done=1; }
if (done==0) { alert("Sorry, no products match your search."); }
}
//-->
</script>

In the body:

<form name=enter_keyword>
<tr>
<td><input type="text" name=keyword value="Search Products" onfocus="if
(this.value==this.defaultValue) this.value='';" size="13">
</td>
</tr>
<tr>
<td colspan=2 align=center>
<input type="image" name="search" Value="search" src="NDSCardStore_files/search2.gif" onClick="Login()">
</td>
</tr>
</table>
</form>

The form works fine 100% when I have the input type as="button" but when changed to image it does not work, and this is added to the url in the address bar when you click the search2.gif image:

?keyword=r4ds&Login%21.x=16&Login%21.y=8&Login%21=search

Please help!
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Submitting form with image as button does not work

Post by andyhoneycutt »

use a standard input button and css to use an image background for the button.

-Andy
User avatar
paqman
Forum Contributor
Posts: 125
Joined: Sun Nov 14, 2004 7:41 pm
Location: Burnaby, BC, Canada

Re: Submitting form with image as button does not work

Post by paqman »

The image input type automatically assumes the role of a submit button. I'm guessing that without a form to submit your image isn't working. Andy's suggestion sounds solid.
Post Reply