Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    817
    Thanks
    43
    Thanked 6 Times in 5 Posts

    set timeout problem

    Is there a reason why this doesn't work?

    Code:
    function delay(){
    soundManager.play('piano','../../media/mp3/piano.mp3'); 
    setTimeout('function(){document.getElementById("tutor").submit();}',4000);
    }
    ...but this does:

    Code:
    function delay1(){
    soundManager.play('piano','../../media/mp3/piano.mp3'); 
    setTimeout('delay2()',4000);
    }
    
    function delay2(){
    document.getElementById("tutor").submit();
    }
    It seems to me that the first one should work too.
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,914
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Suggest you check the position of the closing brace.

    We've clearly still got players coming into the squad who haven't arrived yet. - London Irish RFC Coach

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    817
    Thanks
    43
    Thanked 6 Times in 5 Posts
    It seems right to me. All I am doing is cutting and pasting this:

    Code:
    function delay2(){
    document.getElementById("tutor").submit();
    }
    (without the function name) into this:

    Code:
    function delay(){
    soundManager.play('piano','../../media/mp3/piano.mp3'); 
    setTimeout('FUNCTION GOES HERE',4000);
    }
    Maybe I've stared at it too long!
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,914
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    setTimeout('function(){document.getElementById("tutor").submit(),4000}');
    Last edited by Philip M; 01-14-2013 at 07:49 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    817
    Thanks
    43
    Thanked 6 Times in 5 Posts
    That's confusing Philip because it doesn't work either!

    ...and it doesn't look like the setTimeout pattern.

    Strange. Maybe you can't put a document.getElementById() inside a setTimeout.
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #6
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    setTimeout( 'document.getElementById("tutor").submit()', 4000 );

    but preferably

    setTimeout( function(){ document.getElementById( "tutor" ).submit(); }, 4000 );

  • Users who have thanked Logic Ali for this post:

    tpeck (01-14-2013)

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,914
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by tpeck View Post
    That's confusing Philip because it doesn't work either!

    ...and it doesn't look like the setTimeout pattern.

    Strange. Maybe you can't put a document.getElementById() inside a setTimeout.
    Is the document.getElementById("tutor") the id of a form?

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #8
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    817
    Thanks
    43
    Thanked 6 Times in 5 Posts
    Thanks Logic Ali, those work well.

    Yes, it is the id of a form. Here is the whole thing:

    Code:
    function delay(value){
    soundManager.play('piano','../../media/mp3/piano.mp3'); 
    setTimeout(function(){document.getElementById(value).submit();},4000);
    }
    
    <form id="tutor" method="post" target="_self" action="feedback(tutor).html">
    <input type="submit" onclick="delay('tutor');return false" class="TextArea" value="CLICK HERE">
    </form>
    
    <form id="student" method="post" target="_self" action="feedback(student).html">
    <input type="submit" onclick="delay('student');return false" class="TextArea" value="CLICK HERE">
    </form>
    It may be useful for someone else that wants to play a sound before submitting or, for some other reason, not immediately submit.
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •