36

I'm working on a simple HTML page where I have this image that I want to act as a button.

Here is the code for my image:

<div style="position: absolute; left: 10px; top: 40px;"> 
    <img src="logg.png" width="114" height="38">
</div>

And basically I want to add this functionality into it:

<div>
    <input id="saveForm" name="saveForm" class="btTxt submit" type="submit" value="Submit"/>
</div>

The text on the button itself that says Submit is not needed as my image has the text it needs.

So anyway, is this possible? and if so, How? :)

hichris123
  • 10,145
  • 15
  • 56
  • 70
Kevin
  • 1,435
  • 4
  • 19
  • 27

4 Answers4

63

It sounds like you want an image button:

<input type="image" src="logg.png" name="saveForm" class="btTxt submit" id="saveForm" />

Alternatively, you can use CSS to make the existing submit button use your image as its background.

In any case, you don't want a separate <img /> element on the page.

VoteyDisciple
  • 37,319
  • 5
  • 97
  • 97
13

You could implement a JavaScript block which contains a function with your needs.

<div style="position: absolute; left: 10px; top: 40px;"> 
    <img src="logg.png" width="114" height="38" onclick="DoSomething();" />
</div>
Eric Brotto
  • 53,471
  • 32
  • 129
  • 174
mburm
  • 1,417
  • 2
  • 17
  • 37
4

You could use an image submit button:

<input type="image"  id="saveform" src="logg.png " alt="Submit Form" />
Mudassir Hasan
  • 28,083
  • 20
  • 99
  • 133
0

Here is how I got this to work:

First the css:

    /* resets the button styling */
    button {
      all: unset;
      cursor: pointer;
    }

Then, the html:

<button onclick="submit()">
  <img src="mycoolimage.png" />
</button>

This is cleaner IMO than the input submit approach and allows for ajax without the weird override default submit behavior.

james-see
  • 12,210
  • 6
  • 40
  • 47