Tuesday, March 06, 2012

Submit is not a function

When you see something like this in your JavaScript console beware. It took me a little while to find out what the problem was. But the problem is really simple. Let me explain.

After doing something the user is redirected to the page on which there is a form and one button (just in case if somebody is not using JavaScript). But for the greater part of users I've added some script to click this only one button on a page.

I was trying to do something like this:
<script type="text/javascript">
    $(document).ready(function(){
    document.forms["vm_paypal_form"].submit();
});
</script>
with no success. I was getting this strange message "Submit is not a function".

Trying several combinations - maybe something doesn't exist. Maybe I've mixed mootools and jQuery too much. But at last I've found a solution and I hope that my post will help somebody.

In the form I had (I've got this form from the Internet) an input of type "submit" which name was (?!?) "submit". Very strange in my opinion - so in fact when I was typing .submit() the browser was treating this input as a function - and that's the reason of this creepy error.

So watch out and try to avoid copying forms from the Internet.