settimeout - Set and hold a variable in javascript -
i have 3 javascript functions:
function updatetest() { if (totalmin == "0") { coolvar = "start"; } else { coolvar = "stop"; } } setinterval(updatetest, 1000) var audvar = setinterval(function () { cooltrigger() }, 60000); function cooltrigger() { updateaudio(coolvar); }
i need design function checks state of coolvar same interval, updates html code once upon coolvar=start. should hold , not update variable 60 seconds , returns previous state.
function updateaudio(coolvar) { var a_str; if (coolvar == "start") { a_str = '<audio autoplay source src="audio/coolsound.mp3" type="audio/mpeg"></audio>'; } if (coolvar == "stop") { a_str = '<!--coolsound go off @ 0:00 timer -->'; } document.getelementbyid('audio_span').innerhtml = a_str; } //settimeout(updateaudio, 6000);
at moment using current code, coolvar checked once every 60 seconds update a_str. wanted check coolvar every second update a_str once upon first triggering updateaudio.
what doing wrong? there way achieve this?
Comments
Post a Comment