0

I want an event to be triggered when the image is clicked, but I cannot figure out how to make that happen. Is it possible for an event to be triggered when an image is clicked?

<form>
  <input type="button" name="button" value="Download" onclick="passWord()" class="button"/>
</form>

jsfiddle: https://jsfiddle.net/29mf5wf9/

Random Channel
  • 1,134
  • 10
  • 22
questionador
  • 111
  • 1
  • 3
  • 12
  • You should use an input type "image": http://stackoverflow.com/questions/3381609/button-image-as-form-input-submit-button – Simon Deconde Feb 26 '16 at 16:49

3 Answers3

3

See this fiddle

You can use image instead of button for input type. It will still be a button.

HTML

<input type="image" src="image/path" name="button" value="Download" onclick="passWord()" class="button"/>

According to the docs

The <input type="image"> is a graphical submit button.

See the updated fiddle with a javascript function working..

Lal
  • 14,726
  • 4
  • 45
  • 70
1

You need to specify image in the type.

<form>
    <input type="image" src="http://cdn.sstatic.net/stackexchange/img/logos/so/so-logo.png" name="button" value="Download" onclick="passWord()" class="button"/>
</form> 
WWPTV
  • 11
  • 4
1

Here you can find the information: http://www.w3schools.com/tags/att_input_src.asp

<input type="image" src="your_image.png" name="button" value="Download" alt="Download" onclick="passWord();" class="button" width="your_image_width" height="your_image_height">
Kaan Burak Sener
  • 974
  • 10
  • 19