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?
LVL 4
VincentLawlorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.