954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Input type image, onclick event

For some reason I can have an input type as a button with an onclick event but when I set the input type as image and put an onclick event into it, it doesn't seem to work.

I.e.
This works:

<input type="button" onclick="func('hello')"/>


This doesn't work:

<input type="image" onclick="func('hello')" src="image.jpg"/>
asif49
Posting Whiz in Training
246 posts since Dec 2010
Reputation Points: 5
Solved Threads: 0
 

Try changing the atrribute's place. For example,

<input type="image"  src="image.jpg"  onclick="func('hello')" />


Is the image showing? Is it in the same directory as your HTML file/files?

rotten69
Posting Whiz
346 posts since May 2011
Reputation Points: 3
Solved Threads: 16
 

Look--
1. First of all, look in the JavaScript forum.
2. Onclick = wrong spelling; OnClick = correct spelling
3. Better write

"javascript:hello"


.
4. Image is NOT AN INPUT TYPE: easy way to make that work =

<a href="javascript:hello" ><img src="image.jp<strong>e</strong>g width="" height="" alt="" border="0"></img></a>
jackbauer24
Posting Whiz in Training
234 posts since Oct 2011
Reputation Points: 21
Solved Threads: 2
 

yes, it is correct that onclick is wrong whereas OnClick is right. Javascript is case sensitive language and you have to pay extra attention while writing javascript predefined functions.

EmilyJohnson
Junior Poster in Training
63 posts since Apr 2011
Reputation Points: 10
Solved Threads: 4
 

I suggest you check out this website . It will help you master the basics of HTML and JavaScript.

jackbauer24
Posting Whiz in Training
234 posts since Oct 2011
Reputation Points: 21
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You