?
Solved

How to use image as an submit button

Posted on 2006-07-17
6
Medium Priority
?
388 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 17

Accepted Solution

by:
gops1 earned 100 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 100 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
New style of hardware planning for Microsoft Exchange server.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

764 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