PDA

View Full Version : Javascript submit not working


ventura
12-09-2002, 07:57 PM
Can anyone tell me why I get this error when trying to submit a form via javascript?

JavaScript Error: document.form.submit is not a function



My code is this:
<script language="JavaScript">
function confirmDelete() {
if (confirm("Are you sure you want to delete this product and everything below it?") == true) {
document.form.submit();
}
else {
return false;
}
}
</script>

And my button looks like this:
<input type="button" name="delete" value="Delete?" onClick="return confirmDelete();">

And my form tag looks like this:
<form enctype="multipart/form-data" name="form" method="post" action="/ProductAdminEdit.serv">

beetle
12-09-2002, 08:36 PM
There's a better way than that....just use a regular submit button and this:

<form enctype="multipart/form-data" name="form" method="post" action="/ProductAdminEdit.serv" onsubmit="return confirm('Are you sure you want to delete this product and everything below it?');">

ventura
12-09-2002, 08:39 PM
yeah, i can't do that because i have two other buttons that submit the form.

vegeta
12-09-2002, 10:20 PM
hmmmm

document.form.submit();

works on my page :-/

beetle
12-09-2002, 10:39 PM
You shouldn't used reserved words for naming HTML elements. Instead of form (yes, it's a reserved word) use myForm or form1 or paymentForm or something like that.

Oh, and FYI, the name attribute is deprecated in XHTML for <form> elements. The id attribute should be used instead.