Forum Moderators: open

Message Too Old, No Replies

PROBLEM with onsubmit();

I 'm not able to submit a form as it is showing a javascript error in IE

         

axl chidambaram

6:46 am on Dec 11, 2009 (gmt 0)

10+ Year Member



I 'm not able to submit a form as it is showing a javascript error in IE but works fine in FF. The script is as below.

<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)

astupidname

8:48 am on Dec 11, 2009 (gmt 0)

10+ Year Member



Javascript eror is pointing to document.eventForm.onsubmit();

Yeah, remove that line -you don't need it. document.eventForm.submit(); should do the trick, although is better written as (for greater backwards cross-browser support): document.forms['eventForm'].submit();

rocknbil

5:28 pm on Dec 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Better yet, something like this - pass a reference to the form object like so, and make sure the event handler is in the form tag, not on the button, so if "enter key" is pressed it still does it's thing:


<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>

axl chidambaram

4:46 am on Dec 15, 2009 (gmt 0)

10+ Year Member



Thanks a lot Guys.. The issue is because i have a couple of forms which calls the same function.I did try document.forms['eventForm'].submit(); but still the issue is occuring. Let me check by putting it as function doCheck(form and 'll update you . Thanks a lot again guys ..

rocknbil

5:49 pm on Dec 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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;