I have a HTML form with 3 buttons:
<html:form modelAttribute="registration" id="registration-form" formUrl="/registrationForm">
<input type="hidden" name="id"/>
<html:field name="voucherID" labelCode="label.voucherID" type="text"/>
<html:field name="programID" labelCode="label.programID" type="text"/>
<html:field name="quantity" labelCode="label.quantity" type="text"/>
<html:field name="active" labelCode="label.active" type="checkBox"/>
<div class="form-actions">
<button type="submit" class="btn btn-primary"><spring:message code="button.add"/></button>
<button type="reset" class="btn"><spring:message code="button.cancel"/></button>
<button type="button" class="btn" onclick="remove()"><spring:message code="button.delete"/></button>
</div>
</html:form>
Javascript :
<head>
<%@ include file="header.jsp"%>
<title><spring:message code="title.registration"/></title>
<script type="text/javascript">
function remove(){
alert('test');
var form = document.forms[0];
form.action = "deleteRegistration";
form.submit();
}
</script>
</head>
What I am trying to do is, whenever user press the delete button it should change the value of action to deleteRegistration. However I can’t make this code works, even the alert function is never triggered at all. Where did I do wrong ?
Funny little thing, the
remove()method will run onthisobject, rename the method to _remove or anything else and it should work as expected.