...

View Full Version : onSubmitForm not working



cash1981
05-16-2007, 04:36 PM
Hello, I have a simple JavaScript that for some reason doesnt work.
The problem is when I push the delete image, I get the confirm if I want to delete or not, but when I push ok, I dont get forwarded to the action deleteCompany.jsp

And I cant figure out why.

Here is the code:



<c:forEach var="company" items="${companyList}">
<tr>
<td width="30%"><a href="../index.jsp?action=search&companyId=<c:out value="${company.id}"/>&year=all"><c:out value="${company.name}"/></a></td>
<td width="5%" align="center">
<form name="editCompanyForm" action="editCompany.jsp" method='POST'>
<input type="hidden" name="companyId" value="<c:out value="${company.id}"/>"/>
<input type="hidden" name="returnpage" value="index.jsp"/>
<input type="image" src="images/edit.png" border="0" alt="Rediger Selskap">
</td>
</form>
<td width="5%" align="center">
<form onSubmit="return onSubmitForm();" name="removeForm" method="post">
<input type="hidden" name="companyId" value="<c:out value="${company.id}"/>"/>
<input type="hidden" name="returnpage" value="index.jsp"/>
<input type="image" src="images/delete.png" border="0" value="Slett" alt="Slett" onClick="document.pressed=this.value">
</form>

</td>
</tr>
</c:forEach>

</body>

<script type="text/javascript">
<!--
function onSubmitForm() {
if(document.pressed == "Lagre") {
document.editCompanyForm.action = "editCompany.jsp";
} else if(document.pressed == "Slett") {
var r=confirm("Er du sikker på at du vil slette?\nNB: Alle rapporter til selskapet blir også slettet")
if (r==true) {
document.removeForm.action = "deleteCompany.jsp";
} else {
document.removeForm.action = "?";
}
}

return true;
}
-->
</script>

_Aerospace_Eng_
05-16-2007, 05:29 PM
What exactly is document.pressed? Explain to us what you think that should be.

glenngv
05-16-2007, 08:13 PM
You can do it this way:

<input type="image" src="images/delete.png" border="0" value="Slett" alt="Slett" onclick="document.removeForm.action=(confirm('Er du sikker på at du vil slette?\nNB: Alle rapporter til selskapet blir også slettet'))?'deleteCompany.jsp':'?';" />

cash1981
05-20-2007, 06:00 PM
What exactly is document.pressed? Explain to us what you think that should be.

What I want to happen is that it matches what form which has been submitet, and then I want a dialog box saying, are you sure you want to delete. And then when the user presses yes, I want it to go to the specified action. But it seems like it always just refreshes on the same page.

cash1981
05-20-2007, 06:01 PM
You can do it this way:

<input type="image" src="images/delete.png" border="0" value="Slett" alt="Slett" onclick="document.removeForm.action=(confirm('Er du sikker på at du vil slette?\nNB: Alle rapporter til selskapet blir også slettet'))?'deleteCompany.jsp':'?';" />

Alright thanks Glenn. I will try that when I get back to work tomorrow.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum