Forum Moderators: open
<script language="JavaScript" type="text/javascript">
var iAlreadySubmitted = 0
function doCheck(){
if (iAlreadySubmitted==0){
iAlreadySubmitted=1;
document.eventForm.onsubmit();
// submit the form
document.eventForm.submit();
}
}
Javascript eror is pointing to document.eventForm.onsubmit();
Please let me know if i had something wrong. (Also this is in ColdFusion 5)
<script type="text/javascript">
var iAlreadySubmitted = 0
function doCheck(form){
if (iAlreadySubmitted==0){
iAlreadySubmitted=1;
// note also you can now reference
// form objects like so:
// form.object-name.value or
// form.objectname.selectedIndex
// for selects.
form.submit();
}
return false;
}
</script>
<p>The return false is important, it's what allows
JS to manage the submit without submitting the
form twice. It also allows you to use standard
input type="submit" instead of type="button"
so it still works if JS is disabled.</p>
<form action="your action" method="post" onsubmit="return doCheck(this);">
(your form fields, etc)
</form>
The issue is because i have a couple of forms which calls the same function.
If they have the same name,
<form name="some-name"..>
Your original solution will probably fail because it's going to apply to the first document.formname. However, if you pass a reference to the form object as in my example, it should work, doesn't matter what the form is named or id'ed. This should allow all forms to use the same function.
However, the global iAlreadySubmitted will apply to all submits, which may or may not be desired behavior. I'm suspecting it is, "if this form is already submitted, don't submit others." However you may want to mod it so the user gets some indicator this is the case:
if (iAlreadySubmitted==0){
iAlreadySubmitted=1;
form.submit();
}
else { alert('Already submitted, thank you.');
return false;