Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-14-2013, 06:09 AM   PM User | #1
tpeck
Regular Coder

 
tpeck's Avatar
 
Join Date: Oct 2002
Location: Sydney, Australia
Posts: 771
Thanks: 40
Thanked 5 Times in 4 Posts
tpeck is on a distinguished road
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)
tpeck is offline   Reply With Quote
Old 01-14-2013, 07:17 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 01-14-2013, 07:28 AM   PM User | #3
tpeck
Regular Coder

 
tpeck's Avatar
 
Join Date: Oct 2002
Location: Sydney, Australia
Posts: 771
Thanks: 40
Thanked 5 Times in 4 Posts
tpeck is on a distinguished road
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)
tpeck is offline   Reply With Quote
Old 01-14-2013, 07:43 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
setTimeout('function(){document.getElementById("tutor").submit(),4000}');
__________________

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.

Last edited by Philip M; 01-14-2013 at 07:49 AM..
Philip M is offline   Reply With Quote
Old 01-14-2013, 08:16 AM   PM User | #5
tpeck
Regular Coder

 
tpeck's Avatar
 
Join Date: Oct 2002
Location: Sydney, Australia
Posts: 771
Thanks: 40
Thanked 5 Times in 4 Posts
tpeck is on a distinguished road
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)
tpeck is offline   Reply With Quote
Old 01-14-2013, 10:23 AM   PM User | #6
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 959
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
setTimeout( 'document.getElementById("tutor").submit()', 4000 );

but preferably

setTimeout( function(){ document.getElementById( "tutor" ).submit(); }, 4000 );
Logic Ali is offline   Reply With Quote
Users who have thanked Logic Ali for this post:
tpeck (01-14-2013)
Old 01-14-2013, 10:24 AM   PM User | #7
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 01-14-2013, 11:06 AM   PM User | #8
tpeck
Regular Coder

 
tpeck's Avatar
 
Join Date: Oct 2002
Location: Sydney, Australia
Posts: 771
Thanks: 40
Thanked 5 Times in 4 Posts
tpeck is on a distinguished road
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)
tpeck is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:13 AM.


Advertisement
Log in to turn off these ads.