Skip to main content
July 24, 2009
Question

Error when changing from button to image button...

  • July 24, 2009
  • 1 reply
  • 652 views

Dear friends :

I have a form and a javascript to control the inputs after clicking the "submit" button :

This javascript verifies that some conditions must accomplish when one of the checkboxes is checked, for example. It works perfect when I use the typical submit button: it verifies the checkbox, and tells you to fill a text field when you forgot it... however, as soon as I change the tag of the button in order to customize it with an image, it fails : it does display the javascript verification, does remind you to fill the text field, BUT then it reloads the page and unchecks all the values that already are filled by user...   any explanation ?

This is my typical button:

<input name="button" type="button" onclick="Validar(this.form)" value="Continue" />

This is my image button:

<input type="image" src="img/btn_continue.png" onclick="Validar(this.form)"  width="101" height="22"/>

It is the same !!  why does it fail ?? thanks in advance for your answers...

This topic has been closed for replies.

1 reply

David_Powers
Inspiring
July 24, 2009

It is the same !!  why does it fail ?? thanks in advance for your answers...

No, it's not the same. A form button automatically submits the form if the validation script returns true. An image simply executes the validation script. When you use an image, the validation script needs to submit the form as well.

Using image buttons for forms is generally not a good idea because the form cannot be submitted if JavaScript is disabled.

July 24, 2009

thanks for the reply David, definetly you KNOW

Well.. anyway.. I need to customize my button... what would you suggest ? Thanks in advance,

July 25, 2009

Googling around I found this... thanks a lot,

http://www.webreference.com/programming/css_stylish/