views:

318

answers:

4

I would like to have a submit button which contains text and an image. Is this possible?

I can get the exact look I want with code that looks like:

<button type="button">
<img src="save.gif" alt="Save icon"/>
<br/>
Save
</button>

... but I haven't found a way to have one of those for my forms. Is there a way to do that with an

<input type="submit" ...>

element? Or am I forced to go the image or text way? Thanks for your help!

+2  A: 

input type="submit" is the best way to have a submit button in a form. The downside of this is that you cannot put anything other than text as its value. The button element can contain other HTML elements and content.

Try putting type="submit" instead of type="button" in your button element (source).

Pay particular attention however to the following from that page:

If you use the button element in an HTML form, different browsers will submit different values. Internet Explorer will submit the text between the <button> and </button> tags, while other browsers will submit the content of the value attribute. Use the input element to create buttons in an HTML form.

adrianbanks
+1  A: 

Let's say your image is a 16x16 .png icon called icon.png Use the power of CSS!

CSS:

input#image-button{
    background: #ccc url('icon.png') no-repeat top left;
    padding-left: 16px;
    height: 16px;
}

HTML:

<input type="submit" id="image-button">Text</input>

This will put the image to the left of the text.

Adam Bard
A: 

You're really close to the answer yourself

<button type="submit">
<img src="save.gif" alt="Save icon"/>
<br/>
Save
</button>

Or, you can just remove the type-attribute

<button>
<img src="save.gif" alt="Save icon"/>
<br/>
Save
</button>
elzapp
A: 

Very interesting. I have been able to get my form to work but the resulting email displays:

imageField_x: 80 imageField_y: 17

at the bottom of the email that I get.

Here's my code for the buttons.

    <tr>
      <td><input type="image" src="images/sendmessage.gif" / ></td>
      <td colspan="2"><input type="image" src="images/printmessage.gif"onclick="window.print()"></td>
    </tr>

Maybe this will help you and me as well.

:-)

MoJo