-1

I am trying to use image for button as:

<button name="foo" type="button" value="bar" onclick="AjaxResponse()" > <img src="img.png"> </button>

or

 <button name="foo" type="button" value="bar" onclick="AjaxResponse()" img src="img.png" /> 

Both does not show button with image. It just shows small icon, which performs correct operation on click. But why the image could not be seen?

user123
  • 5,269
  • 16
  • 73
  • 121

5 Answers5

3

Just use the <img> tag and add onClick to it:

<img src="img.png" onclick="AjaxResponse()" />

In addition, you can set the width and height according to your picture's dimensions:

<img src="img.png" onclick="AjaxResponse()" width="100" height="100" />

However, the CSS background-image property is probably the best solution. There you can also adjust width and height.

Georg
  • 378
  • 1
  • 3
  • 10
  • the img element doesn't have a closing tag :-( –  Aug 13 '13 at 06:25
  • @jeff I normally use ´XHTML´, where all tags have to be closed, but I edited the answer. – Georg Aug 13 '13 at 06:45
  • This correct syntax is XHTML has been depreciated and hasn't been updated since 1999. Use html 5 syntax. –  Aug 13 '13 at 06:57
2

Specify the width and height correctly.Like

<img src="something" width=200 height=200>

Otherwise use div tag to create custom button with the help of CSS.

Go through this you can get some idea Click here

Community
  • 1
  • 1
nmkyuppie
  • 1,456
  • 1
  • 14
  • 30
1

There is no need of PHP, this is in your HTML part and you can't do this without CSS or you can use:

<input type="image" ...

to know more read the following link: Input Types

OR take a look on CSS: background

jogesh_pi
  • 9,762
  • 4
  • 37
  • 65
1
<input type="image" src="FILEPATH" onclick="AjaxResponse()" name="foo" id="button" value="bar">
KevBot
  • 17,900
  • 5
  • 50
  • 68
1

if you don't want to use css, you can use the input like this,

input type="image" src="img.png" name="foo" type="button" alt="bar" onclick="AjaxResponse()"  
Kishan_KP
  • 4,488
  • 6
  • 27
  • 46