VincentLawlor
asked on
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='up date'></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='up date'"></t d>
</tr>
<tr>
<td>Another thing</td>
<td><input name="ID" value="10" type="image" src="img/edit_icon.gif" onClick="document.test.cmd .value='up date'"></t d>
</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='up date'"></t d>
</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?
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
</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
</tr>
<tr>
<td>Another thing</td>
<td><input name="ID" value="10" type="image" src="img/edit_icon.gif" onClick="document.test.cmd
</tr>
<tr>
<td>Yet another thing</td>
<td><input name="id" value="11" type="image" src="img/edit_icon.gif" onClick="document.test.cmd
</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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
exactly
ASKER
To the rescue again fargo.
Does an image input element not have a value attribute?
Does an image input element not have a value attribute?
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.
In other words, use plain javascript and be happy.
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
http://www.jguru.com/faq/view.jsp?EID=87441
ASKER
Will do.
Again many thanks.
Again many thanks.
ASKER
So what you are saying is I could/should use something like:
<script type="text/javascript">
function update(cmd,itm){
document.test.cmd.value=cm
document.test.item.value=i
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',<
</tr>
<%}%>
....
<input type="hidden" name="cmd">
<input type="hidden" name="item">
...