Javascript - posting forms with images.

Many developers have asked how to use images to submit forms. Of course, the "input" tag allows this. However, we often times want to submit the form differently depending on which image button was clicked.

Many developers have asked how to use images to submit forms. Of course, the "input" tag allows this. However, we often times want to submit the form differently depending on which image button was clicked.

Here's a little sample function to demonstrate how to perform this task in JavaScript. This sample shows you how to send a different querystring variable for which you can react to when the page is posted either to itself or another page.


<input type=image src=/images/EditAccount.jpg border=0>
<a href=javascript:EditAccount('1'); ><img name=EditAccount1 src=/images/EditAccount1.jpg border=0></a>
<a href=javascript:EditAccount('2'); ><img name=EditAccount2 src=/images/EditAccount2.jpg border=0></a>

<SCRIPT language=JavaScript>
function EditAccount(sOption)
{ document.frmSubmit.action='/accountlogin.asp?POST=' + sOption;
document.frmSubmit.submit();
}
</SCRIPT>


Submission Date:  9/23/2005 2:48:31 PM
Submitted By:  Robbe Morris
My Home Page:  http://www.robbemorris.com

By Robbe Morris   Popularity  (340 Views)
Picture
Biography - Robbe Morris
Robbe has been a Microsoft MVP in C# since 2004. He is also the co-founder of NullSkull.com which provides .NET articles, book reviews, software reviews, and software download and purchase advice.  Robbe also loves to scuba dive and go deep sea fishing in the Florida Keys or off the coast of Daytona Beach. Microsoft MVP