Solved

How to use image as an submit button

Posted on 2006-07-17
6
359 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 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
excpetion with multiple catch 11 138
Prevent Firefox page from going to the background when clicking a spreadsheet link 17 71
by zero exception 10 79
mysql jsp example issue 32 92
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
The goal of this blog is: - To define the incident management process - To go over the key elements of an incident management system - To look into incident alert management tools that integrate with ConnectWise.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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