2

This is my js script:

<script language="javascript">

setTimeout ( "autoForward()" , 5000 );
function autoForward() {
    var submitForm = $("#submitfrm").find("form");
    submitForm.submit();
}
</script>

And the error occurs at:

var submitForm = $("#submitfrm").find("form");

I'm using jQuery and I noticed this answer on SO but when I tried to add it:

<script language="javascript">
jQuery(document).ready(function ($) {

setTimeout ( "autoForward()" , 5000 );
function autoForward() {
    var submitForm = $("#submitfrm").find("form");
    submitForm.submit();
}

});
</script>

I get:

Uncaught ReferenceError: autoForward is not defined 

I also tried to switch the function's position but it didn't help. What's wrong here?

Community
  • 1
  • 1
Tom
  • 9,275
  • 25
  • 89
  • 147
  • In snippet two, you used quotes around your function, meaning you're targeting a global function. You didn't define the function in the global scope. Better to not target a global function and instead target the one in the scope. – Kevin B Jan 10 '14 at 16:12

1 Answers1

7

Try:

setTimeout (autoForward , 5000 );

instead of:

setTimeout ("autoForward()" , 5000 );

You don't need any quote " or bracket () here.

Felix
  • 37,892
  • 8
  • 43
  • 55