questionador
questionador

Reputation: 113

Input type button with image

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/

Upvotes: 0

Views: 3009

Answers (3)

Lal
Lal

Reputation: 14810

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..

Upvotes: 3

Kaan Burak Sener
Kaan Burak Sener

Reputation: 994

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">

Upvotes: 1

WWPTV
WWPTV

Reputation: 11

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> 

Upvotes: 1

Related Questions