0

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

Edited by asif49: n/a

5
Contributors
5
Replies
19
Views
5 Years
Discussion Span
Last Post by ojemuyiwa
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?

1

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[B]e[/B]g width="" height="" alt="" border="0"></img></a>
0

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.

Edited by EmilyJohnson: formatting text

0

Please delete these mis-leading views. html attributes are defined in w3c as per doc types e.g. xhtml 1.1 strict, html5, xhtml 1.0 Transitional etc. "You can find this at the top of your document". Ideally all attributes are lower case i.e. onclick. Now the real issue you are finding here depends on the input type. If you test with input type submit and experience the same thing it is because your controls are in a form control. This is by design that html forms are submitted with those kind of controls. a return false in your onclick function may do the trick.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.