Hi Guys,
I'm new to Javascript and have a couple of questions that I hope
someone could quickly answer for me.
First, I'm trying to modify an example Ajax script to fit my needs.
The script is located here:
http://ajaxify.com/run/time/periodicRefresh/
I'm trying to display return data from my existing script, and I'm a
little confused on how to display the returned variables within my Web
page. Currently the author of the 'example' script has the following
code embedded within the HTML:
<form action="/">
<div id='customTimeL abel' class='timeLabe l'></div>
<div align="center">
<input type="hidden" id="customTime " value="Refresh" />
</div>
</div>
<div align="center"> </div>
</form>
The author displays this form and also has a button to create an
additional action when the button is pressed. I removed the button and
just want to display the variables, I do not want to have a form as he
did. Is there a alternate way of doing this? When I embed this in my
code it takes up too much real estate on the Web page.
Second, there is a setInterval timer used that periodically goes to
the server and refreshes the data. I have created a function,
'volup()' that stops the timer 'clearInterval( interval)' and displays
a new message for a few seconds, then my script is supposed to restart
the setInterval timer. Everything seems to work ok with the exception
of the setInterval restart. Could someone have a look at my code and
give me some suggestions? The problem is on the last line of the
volup() function, this command never seems to restart the timer. Also
I've noticed that my setTimeout timer can become very erratic at
times, not following my specified timing of 3 seconds, but this only
happens once in a great while and is very intermittent.
Thanks in advance,
Shawn
ajaxCaller.shou ldDebug = false;
var timeURL = "cgi-bin/test?h=1";
//var timeURL = "tickercontent. txt";
window.onload = function() {
// $("defaultTime" ).onclick=reque stDefaultTime;
// $("customTime") .onclick=reques tCustomTime;
requestCustomTi me();
interval=setInt erval(requestCu stomTime, 1500);
}
function volup(){
clearInterval(i nterval)
showCustomTime( "Change Source", "");
a="requestCusto mTime();"
setTimeout(a, 3000);
clearTimeout(t)
interval=setInt erval(requestCu stomTime, 1500)
}
function requestCustomTi me() {
var callingContext = Math.round(Math .random() * 100);
ajaxCaller.getP lainText(timeUR L, showCustomTime) ;
}
function showCustomTime( text, callingContext) {
var customTimeLabel = $("customTimeLa bel");
customTimeLabel .innerHTML = text + "." + callingContext;
}