Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    215
    Thanks
    14
    Thanked 0 Times in 0 Posts

    button or image for submit

    Hello all. I have read many places on how to use an image for a submit button. I have the following code:

    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:

    Code:
    <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

  • #2
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    return false to stop the form submitting, I believe.

  • Users who have thanked Apostropartheid for this post:

    parallon (05-14-2008)

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    215
    Thanks
    14
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •