Solved

How to use image as an submit button

Posted on 2006-07-17
6
322 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
Comment Utility
<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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A procedure for exporting installed hotfix details of remote computers using powershell
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 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

13 Experts available now in Live!

Get 1:1 Help Now