• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 322
  • Last Modified:

Image as a submit button

Hi All,

I have a form populated with data from a MySQL database in the form of a table.

Each row in the table has a Description and an edit image.
I want to be able to use the image to submit a value back to my servlet.
Something like below:

<form name="test" action="/blah/blahblah" method="post">
...
...
<%
for(int i = 0; i<somearray.length;i++){
    SomeClass cls = somecollection[i];
%>
<tr>
<td><% cls.getDescription() %></td>
<td><input name="ID" type="image" src="img/edit_img.gif" value="<% cls.getID() %>"  onClick="document.test.cmd.value='update'></td>
</tr>
<%}%>

Everything looks fine the description and image are displayed and the page source looks fine:

<tr>
<td>Something</td>
<td><input name="ID" value="9" type="image" src="img/edit_icon.gif" onClick="document.test.cmd.value='update'"></td>
</tr>

<tr>
<td>Another thing</td>
<td><input name="ID" value="10" type="image" src="img/edit_icon.gif" onClick="document.test.cmd.value='update'"></td>
</tr>

<tr>
<td>Yet another thing</td>
<td><input name="id" value="11" type="image" src="img/edit_icon.gif" onClick="document.test.cmd.value='update'"></td>
</tr>

However when I hit one of the images the parameter ID is not set.
Doing the same thing with a radio input element and a submit button works.

Any ideas?
0
VincentLawlor
Asked:
VincentLawlor
  • 4
  • 3
1 Solution
 
fargoCommented:
u can use the following way, using the javascript function to submit the form

function update(){
document.test.cmd.value='update';
document.test.submit();
}

<input type.........onClick="update();"/>

What i m also missing is where is the cmd param??

0
 
VincentLawlorAuthor Commented:
It's a hidden input element used to determine the next command the servlet should execute.

So what you are saying is I could/should use something like:

<script type="text/javascript">
function update(cmd,itm){
document.test.cmd.value=cmd;
document.test.item.value=itm;
document.test.submit();
}
</script>

<form name="test" action="/blah/blahblah" method="post">
...
...
<%
for(int i = 0; i<somearray.length;i++){
    SomeClass cls = somecollection[i];
%>
<tr>
<td><% cls.getDescription() %></td>
<td><input name="ID" type="image" src="img/edit_img.gif" value="<% cls.getID() %>"  onClick="update('update',<% cls.getID() %>);"></td>
</tr>
<%}%>
....

<input type="hidden" name="cmd">
<input type="hidden" name="item">
...
0
 
fargoCommented:
exactly
0
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!

 
VincentLawlorAuthor Commented:
To the rescue again fargo.

Does an image input element not have a value attribute?
0
 
fargoCommented:
image input element does have a value attribute. But when u use image as submit button, the x,y coordinates of the image are submitted. You may use different names for the images and then parse the params to get the value.

In other words, use plain javascript and be happy.
0
 
fargoCommented:
i found one good example and explanation of what i said in my last post (with example)
http://www.jguru.com/faq/view.jsp?EID=87441
0
 
VincentLawlorAuthor Commented:
Will do.

Again many thanks.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now