Solved

How to use image as an submit button

Posted on 2006-07-17
6
331 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
change size of out.write buffer 1 87
xjc and jaxb 2 90
dynamic reloading of jsp in jetty 2 118
maven project jars 7 50
A customer recently asked me about anti-malware and the different deployment options available for his business. Daily news about cyberattacks, zero-day vulnerabilities, and companies that suffered a security breach made him wonder if the endpoint a…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now