The image button inside the form, do not want to send

I have a form with an image button inside it, and this image button submits the form. How to override this functionality?

<form><input type="image" src="/images/arrow.png" id="imageButton" onClick="javascript:autofill();"/></form> 
+8
html submit button forms
source share
6 answers

Why not just have an image? return false will also stop the form submit action.

 <form><input type="image" src="/images/arrow.png" id="imageButton" onClick="autofill();return false;"/></form> 
+15
source share

just return false after autofill () function.

 onclick="autofill();return false;" 
+8
source share

Why use an input element at all? I would think that just using an image with an onclick event would be more appropriate if you don't want to call submit or reset behavior

 <image src="/images/arrow.png" onclick="javascript:autofill();" width="xxx" height="xxx" alt="Autofill" /> 
+6
source share

By clicking on the button inside the form, submit the default form. To change it, you must define a button with type = "button". Then you can add the img element inside it. This is the best way I've found for this.

 <form> <button type="button" id="imageButton" onclick="javascript:autofill();"> <img src="images/arrow.png"> </button> </form> 
+2
source share

Try using event.preventDefault to abort the dispatch of an event by clicking a button

eg:

 $("#idButton").click(function(event) { if(!valid) { //stopEvent event.preventDefault(); } else { //submit your form $("#form").submit(); } }); 
0
source share

Do you want to disable your button after clicking the submit / image button?

if you use php , you can use the code below or add disabled="disabled" to disable the button while you save it in your input form.

  <?php if (isset($disable) && $disable === true) echo ' disabled="disabled"'; ?> 

how to add my code

if you use your line of code with image type:

try:

<form><input type="image" src="/images/arrow.png" id="imageButton" onClick="javascript:autofill();" <?php if (isset($disable) && $disable === true) echo ' disabled="disabled"'; ?> /></form>

Please read this answer from me (jagb) too, if you want to use an image without javascript, the necessary css can be found there too.

0
source share

All Articles