Hi,
I am using Struts1.1
What i want to do : I want to delete a customer by clicking on 'Delete' link. But before deleting the customer i want a confirmation message. If yes then delete, if no then do not delete the customer.
I have implemented the above functionality as follows:
My
jsp page:
<logic:iterate id="CustInfo" name = "CustInfo">
<tr>
<td >
<%=i %>
</td>
<td >
<bean:write name ="CustInfo" property="CID"/>
</td>
<td >
<bean:write name ="CustInfo" property="CNAME"/>
</td>
<td >
<bean:write name ="CustInfo" property="ADDR"/>
</td>
<td>
<html:link action="edit.do?method=prepareEdit" paramName="CustInfo" paramProperty="CID" paramId="CID"> Edit/ </html:link>
</td>
<td>
<html:link action="delete.do?method=deleteCustomer" onclick="alertMessage();" paramName="CustInfo" paramProperty="CID" paramId="CID">Delete</html:link>
</td>
</tr>
<% i++; %>
</logic:iterate>
function alertMessage()
{
alert("Inside alert Mesage");
var answer = confirm("Do you want to delete this customer?");
var CID = document.forms[0].CID.value;
alert(CID);
if(answer)
{
action = delete.do?method=deleteCustomer?CID;
alert(Customer deleted successfully!);
}
}
If i try to remove the action property from <html:link> it is giving an error message saying any 1 of href/ action tag should be present.
But i am not getting any confirmation box and the record is getting deleted.
What am i doing wrong?
Thanks