Page 1 of 1

theform.submit not a function

Posted: Fri Mar 02, 2007 3:48 pm
by kendall
I've seen this in the forum alot but none of the solutions provided are working so maybe there is a different reason for my error

I have built a form validation script that on a "onsubmit=checkForm() return false;" the script validates the form and submits it on a successful validation

Code: Select all

function checkForm(){
theform = document.forms[0];

// validation

if(!error)
theform.submit();
}
I have used this script over and over on many forms and has worked without flaws

however on this particular form...

1. the html is actually being included via php.
2. there are other javascripts being included (however, no errors are being reported and are not related to the form). This includes some ajax scripting.

the validation function executes as it should as trying to submit an empty form will bring up validation error alerts without script errors. but on successfull validation the debugging in firefox shows a
theform.submit is not a function
in the console

i did a

Code: Select all

alert(theform.name);
and was able to get the name of the form successfully so it cant be that it isnt finding the form.

is there any policy concerning this that needs to be followed? I do not see a reason why there would be such an error if the functions recognises the form

feyd | it's

Code: Select all

 not [code="..."] :P[/color]

Posted: Fri Mar 02, 2007 4:36 pm
by feyd
When "theform.submit is not a function" appears, an element named "submit" is not far behind. :)

Posted: Sat Mar 03, 2007 10:36 am
by kendall
ooohhhhhhhh....

8O

Posted: Sat Mar 03, 2007 10:40 am
by nickvd
Inside the event handler, 'this' refers to the object that triggered the event.

Code: Select all

function checkForm(){
// validation
error = false;

if (!error) this.submit();

} 

Posted: Mon Mar 05, 2007 7:12 am
by kendall
nickvd wrote:Inside the event handler, 'this' refers to the object that triggered the event.

Code: Select all

function checkForm(){
// validation
error = false;

if (!error) this.submit();

} 

Hmmm... are you sure...I ttried it but im getting a javascript alert on "this" and it turns up [object window] and gives me no reference to the form

im using the forms "onsubmit" to trigger the form validation.

Posted: Mon Mar 05, 2007 7:33 am
by kendall
When you use

Code: Select all

form.submit()
does the "submit" button value get $_POSTED?
[/syntax]

Posted: Mon Mar 05, 2007 7:40 am
by feyd
Only if that is the browser's behavior. Some don't submit the button unless clicked. This is why I tell people to never look for the submit button when attempting to detect a submission.

Posted: Mon Mar 05, 2007 7:45 am
by kendall
feyd wrote:Only if that is the browser's behavior. Some don't submit the button unless clicked. This is why I tell people to never look for the submit button when attempting to detect a submission.

oooohhhhhh 8O