...

View Full Version : button or image for submit



parallon
05-14-2008, 09:49 PM
Hello all. I have read many places on how to use an image for a submit button. I have the following code:


<input name="btnAddCustomer" type="image" id="btnAddCustomer" onClick="Javascript:AddCustomer();" value="Add Customer" SRC="../Images/Add.gif" ALT="Add to Customer List" width="13" height="13">

Here is the AddCustomer() function:


<script>
function AddCustomer() {

var i = confirm ("Are you sure that you want to add this customer to the Customer List?");
if (i==true)
{
document.frmMain.submit();
alert("Customer has been added to the database.");
}
}


</script>

.. well, this is causing strange issues. It seems that when I use an image for the button, no matter what I choose on the Confirm action, it still submits the form. If I just change the type from Image to Button, and nothing else, then js functions properly.

Any suggestions would be greatly appreciated.

Parallon

Apostropartheid
05-14-2008, 10:20 PM
return false to stop the form submitting, I believe.

parallon
05-14-2008, 10:58 PM
Thank you. That worked, although I had to put it in the <form> tag. I figured it would have went in the script, but when I did that, the same thing happened. Could you explain why I needed it on the form tag? Is that to make sure that JS is the one submitting the form and not the button?

Thanks again,

Parallon



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum