Solved

How to use image as an submit button

Posted on 2006-07-17
6
347 Views
Last Modified: 2008-02-01
Hi,

I am getting java.lang.IllegalStateException Error When I try to use an image as submit button.
<INPUT TYPE="image" SRC="img/hgbutt.gif" HEIGHT="24" WIDTH="129" BORDER=0 ALT="picture button">. And I am using appache tomcat as a web server.

/*
This is the JSP code below. Is there any way I can use image as an submit button in my JSP form ?
*/

<form action="RedirectTest.jsp" method="POST">
  <select name="Communications">
    <option value="http://www.agr.gc.ca/index_e.php"> AAFC Online </option>
      <option value="/Intranet/BasicTemplateAction.do?action=toc&tocId=252&lang=e"> E-Commuications-RelativePath-Intranet

(Relative)</option>
      <option value="http://training.proquest.com/trc/training/en/peervsscholarly.doc"> Word Doc </option>
      <option value="http://agrisource1.agr.gc.ca/Intranet/BasicTemplateAction.do?action=toc&tocId=595&lang=e"> HR Contacts

</option>
      <option value="http://agrisource1.agr.gc.ca/others/WCSC_April11_e.pdf"> PDF Document </option>
  </select>
<INPUT TYPE="image" SRC="img/hgbutt.gif" HEIGHT="24" WIDTH="129" BORDER=0 ALT="picture button">
</form>
0
Comment
Question by:johnny007
6 Comments
 
LVL 17

Accepted Solution

by:
gops1 earned 25 total points
ID: 17121634
<input type="image" is very buggy still across some broswers. When dealing with forms, most of  us don't like taking the chance of not having it funtion properly.

Use this instead:

<a href="javascript:document.forms[0].submit()" onClick="return false;"><img src="img/hgbutt.gif" BORDER="0" WIDTH="129" HEIGHT="24"></a>

0
 
LVL 2

Assisted Solution

by:vikrant4u2
vikrant4u2 earned 25 total points
ID: 17121711
gops1 is right

Or this will also work

<img src="img/hgbutt.gif" BORDER="0" WIDTH="129" HEIGHT="24" onClick="javascript:document.forms[0].submit()">
0
 
LVL 8

Expert Comment

by:kaliyugkaarjun
ID: 17121760
simple example

<form> <input type='image' name='a1' src='button.gif' value='submit'> <input type='image' name='a2' src='button.gif' value='submit'> <form>
result
<% if (request.getParameter("a1.x")!=null) out.println("b1 pressed"); if (request.getParameter("a2.x")!=null) out.println("b2 pressed"); %>



few links to understand the usage

http://forum.java.sun.com/thread.jspa?threadID=584454&messageID=2995840

http://www.mail-archive.com/struts-user@jakarta.apache.org/msg15597.html
0
 
LVL 10

Expert Comment

by:PSSUser
ID: 17258696
Alternatively you could use the Button element http://www.w3schools.com/tags/tag_button.asp
<button type="submit">
<img src="img/hgbutt.gif" height="24" width="129" border=0 alt="picture button" />
</button>

Note you may need to style the button to get rid of padding/margin and border depending on what look you're going for.

Something else using these buttons allows you to do to using html similiar to this
<button type="button" onClick="javascript:addToBasket('product_id');" class="AddToBasket">
  <span class="AddToBasketText">Add to Basket</span>
</button>
You can then just with style affect whether the text displays or an image is used i.e. you cat set class AddToBasketText to display: none and set a backgound-image on class AddToBasket.

This has been great for me as we host several sites based on templates and some may want text buttons others image based buttons. This allows you to make the change with styles only.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Apache server configuration 7 87
hashcode is calculated on the basis of value object 2 118
Java Exception example issues 11 84
How  can  i  resolve  HTTP Status 404 -? 8 42
Most MSPs worth their salt are already offering cybersecurity to their customers. But cybersecurity as a service is wide encompassing and can mean many things.  So where are MSPs falling in this spectrum?
ConnectWise and their customers need to ensure critical alerts automatically reach the right person at the right time. MSP superheros efficiently respond to these alerts key is providing automatic, intelligent alerting that generates a complete audiā€¦

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question