/    Sign up×
Community /Pin to ProfileBookmark

Textarea changing

Hi

I’m not the best at programming, and I taught myself, and I’m stuck with this one. What I want it, I have a textbox stopwatch (edited script) that I use for work, and I would like to make either the textbook backgrounds color or the text color change when the time goes past a certain value, for instance, after 800 seconds the text turns red.

I have looked everywhere for this, i figured it would be simple, but as I cant find anything on it, I’m beginning to think it does not exist. I posted the code I have below.

[CODE]

<html>
<head>
</head>

<body bgcolor=”#000000″>

<center>

<form name=exf1> <font color=”#FFFFFF”>
hour: <input size=1 type=text name=hour value=”0″ onfocus=blur()>&nbsp;

min: <input size=2 type=text name=tmin value=”0″ onfocus=blur()>&nbsp;

sec: <input size=3 type=text name=sec value=”0″ onfocus=blur()>&nbsp;
</font>

<br><br>

<input type=button value=”Start / Reset” onclick=”startIt()”>
<input type=button value=”Stop” onclick=”stopTimers()”>
</form>

<script>
var _myTimer_ms = null;
var _myTimer_s = null;
var _myTimer_m = null;
var _myTimer_h = null;
function updateS() { document.exf1.sec.value = (1+parseInt(document.exf1.sec.value)) }
function updateM() { document.exf1.tmin.value = (1+parseInt(document.exf1.tmin.value)) }
function updateH() { document.exf1.hour.value = (1+parseInt(document.exf1.hour.value)); }
function startIt() {
stopTimers();
resetTime();
_myTimer_s = setInterval(“updateS()”,1000);
_myTimer_m = setInterval(“updateM()”,1000*60);
_myTimer_h = setInterval(“updateH()”,1000*60*60);
}
function stopTimers() {
clearInterval(_myTimer_s);
clearInterval(_myTimer_m);
clearInterval(_myTimer_h);
}
function resetTime() {
document.exf1.sec.value=0;
document.exf1.tmin.value=0;
document.exf1.hour.value=0;
}

</script>

</center>

</body>
</html>

[/CODE]

Sorry bit of a mess.
Thank You in advance
kirt

to post a comment
JavaScript

11 Comments(s)

Copy linkTweet thisAlerts:
@KorMar 10.2008 — <i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;meta http-equiv="Content-Style-Type" content="text/css"&gt;
&lt;meta http-equiv="Content-Script-Type" content="text/javascript"&gt;
&lt;style type="text/css"&gt;
#center{
width:210px;
margin-left:auto;
margin-right:auto;
}
#center div{
width:70px;
float:right;
}
&lt;/style&gt;
&lt;script type="text/javascript"&gt;
var changeTime=4000;//time in milliseconds after the text changes its color
var changeColor='#ff0000';//the changed color (hexa)
var setT=null;
function initC(){
setT?clearTimeout(setT):null;
var spans=document.getElementById('center').getElementsByTagName('span'), i=0, sp;
while(sp=spans[i++]){
sp.style.color='#000000';
}
startC(-1,0,0)
}
function startC(s,m,h){
var time=[];
s++;
if(s==60){s=0;m++}
if(m==60){m=0;h++}
time[0]=h&lt;10?'0'+h:h;time[1]=m&lt;10?'0'+m:m;time[2]=s&lt;10?'0'+s:s;

var spans=document.getElementById('center').getElementsByTagName('span'), i=0, sp;
while(sp=spans[i++]){
sp.firstChild.nodeValue=time[i-1];
if(s*1000&gt;=changeTime){
sp.style.color=changeColor;
}
}

setT=setTimeout(function(){startC(s,m,h)},1000);
}
function stopC(){
clearTimeout(setT)
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="center"&gt;
&lt;div&gt;hour: &lt;span&gt;00&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;min: &lt;span&gt;00&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;sec: &lt;span&gt;00&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style="clear:both"&gt;
&lt;form&gt;
&lt;input type="button" value="Start / Reset" onclick="initC()"&gt;
&lt;input type="button" value="Stop" onclick="stopC()"&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@KirtanglauthorMar 10.2008 — Give this man a medal...

thank you mate, you have helped me out a lot here, and easy to edit the colors and everything as well,

Hope I can repay you some time ?

Kirt
Copy linkTweet thisAlerts:
@KirtanglauthorMar 10.2008 — Sorry to double post, didnt know how to edit posts.

How would I go about setting a time of 890 seconds or 890000 MS, it seeps to cut off after 60 seconds, because the seconds change back to 0 as the 1 moves over to the minute...
Copy linkTweet thisAlerts:
@KorMar 10.2008 — You are right. Ok, I have passed another, independent argument, k, witch will track only the seconds:
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;meta http-equiv="Content-Style-Type" content="text/css"&gt;
&lt;meta http-equiv="Content-Script-Type" content="text/javascript"&gt;
&lt;style type="text/css"&gt;
#center{
width:210px;
margin-left:auto;
margin-right:auto;
}
#center div{
width:70px;
float:right;
}
&lt;/style&gt;
&lt;script type="text/javascript"&gt;
var changeTime=70000;//time in milliseconds after the text changes its color
var changeColor='#ff0000';//the changed color (hexa)
var setT=null;
function initC(){
setT?clearTimeout(setT):null;
var spans=document.getElementById('center').getElementsByTagName('span'), i=0, sp;
while(sp=spans[i++]){
sp.style.color='#000000';
}
startC(-1,0,0,-1)
}
function startC(s,m,h,k){
var time=[];
s++;k++
if(s==60){s=0;m++}
if(m==60){m=0;h++}
time[0]=h&lt;10?'0'+h:h;time[1]=m&lt;10?'0'+m:m;time[2]=s&lt;10?'0'+s:s;

var spans=document.getElementById('center').getElementsByTagName('span'), i=0, sp;
while(sp=spans[i++]){
sp.firstChild.nodeValue=time[i-1];
if(k*1000&gt;=changeTime){
sp.style.color=changeColor;
}
}

setT=setTimeout(function(){startC(s,m,h,k)},1000);
}
function stopC(){
clearTimeout(setT)
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="center"&gt;
&lt;div&gt;hour: &lt;span&gt;00&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;min: &lt;span&gt;00&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;sec: &lt;span&gt;00&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style="clear:both"&gt;
&lt;form&gt;
&lt;input type="button" value="Start / Reset" onclick="initC()"&gt;
&lt;input type="button" value="Stop" onclick="stopC()"&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@KirtanglauthorMar 10.2008 — Thanx a lot man, again.

I should of asked this at the start, But if its possible (and not to much trouble) could we let the seconds and minutes keep counting, so when they hit the 60 seconds the minute rolls over but the seconds continues through 61, 62, 63 etc.

I was working on it before, which actually fixed the 59 second max color change (sorry, found it after you posted) but the only way I could get the minutes to go up was to make multiple if(s==60){s=0;m++} lines, so for instance:

[CODE]
if(s==60){s=0;m++}
if(s==120){s=0;m++}
if(s==180){s=0;m++}
if(s==240){s=0;m++}
[/CODE]


and so on, not pretty i know, but remember I'm a noob lol, I tried to make an array, but it killed the code.

If its to much trouble don't worry, ill continue playing with the new code you gave me. I have never posted on a forum before asking for help, I usually do the trial and error approach lol.

Thank you again

Kirt
Copy linkTweet thisAlerts:
@KorMar 10.2008 — But it looks illogical... Why to keep seconds go on over 60 if you have a field for minutes which changes each 60 seconds... Maybe you need another separate field to show only the total seconds:
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;meta http-equiv="Content-Style-Type" content="text/css"&gt;
&lt;meta http-equiv="Content-Script-Type" content="text/javascript"&gt;
&lt;style type="text/css"&gt;
#center{
width:400px;
margin-left:auto;
margin-right:auto;
}
#center div{
width:100px;
float:left;
}
&lt;/style&gt;
&lt;script type="text/javascript"&gt;
var changeTime=70000;//time in milliseconds after the text changes its color
var changeColor='#ff0000';//the changed color (hexa)
var setT=null;
function initC(){
setT?clearTimeout(setT):null;
var spans=document.getElementById('center').getElementsByTagName('span'), i=0, sp;
while(sp=spans[i++]){
sp.style.color='#000000';
}
startC(-1,0,0,-1)
}
function startC(s,m,h,k){
var time=[];
s++;k++
if(s==60){s=0;m++}
if(m==60){m=0;h++}
time[0]=h&lt;10?'0'+h:h;time[1]=m&lt;10?'0'+m:m;time[2]=s&lt;10?'0'+s:s;time[3]=k&lt;10?'0'+k:k;
var spans=document.getElementById('center').getElementsByTagName('span'), i=0, sp;
while(sp=spans[i++]){
sp.firstChild.nodeValue=time[i-1];
if(k*1000&gt;=changeTime){
sp.style.color=changeColor;
}
}
setT=setTimeout(function(){startC(s,m,h,k)},1000);
}
function stopC(){
clearTimeout(setT)
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="center"&gt;
&lt;div&gt;hour: &lt;span&gt;00&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;min: &lt;span&gt;00&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;sec: &lt;span&gt;00&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;total sec: &lt;span&gt;00&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style="clear:both"&gt;
&lt;form&gt;
&lt;input type="button" value="Start / Reset" onclick="initC()"&gt;
&lt;input type="button" value="Stop" onclick="stopC()"&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@KirtanglauthorMar 10.2008 — hmm... reason I wanted the seconds is I was going to use this for work, see I work as an online and over the phone computer tech, and all calls, and chat sections are all measure in seconds, 890 seconds is supposed to be our limit, why thy don't just do 900 seconds I don't know. But obviously not everyone can instantly convert seconds to minutes. so I also wanted the minutes so I could see how long I have been in contact for.

But i just checked your new master piece, and I have to say, its more impressive than what I was thinking, you do this for a living by chance lol? well this is probably simple stuff for you I'm sure, and its helped me a lot thank you, it should be perfect now, all I have done is change the colors, color change time and moved the total seconds. again many thanks ?

Kirt
Copy linkTweet thisAlerts:
@KorMar 10.2008 —  you do this for a living by chance lol? [/QUOTE]
Yes. I am a web designer (Photoshop), client-side programmer (HTML, CSS, Javascript, XML, DOM, Ajax) and basic server-side programmer (php/MySQL)
Copy linkTweet thisAlerts:
@KirtanglauthorMar 11.2008 — Thought as much, you built them scripts from ground up in minutes.

I used the tool at work today works a treat, How hard would it be to add a pause button, I looked at it, and used a mix of you start/reset button and the stop button, so it would stop, not clear, than on click start but not clear, but when I tried it, none of the buttons worked. eh.. Ill work at it...

Kirt

Edit: Just checked its because I changed the buttons to the type=Image, that why nothing worked, with the pause function they work, but it doesn't pause, it stops, but will not restart again. I wish I stayed in my IT classes now lol.
Copy linkTweet thisAlerts:
@KorMar 11.2008 — input type="image" act like a submit button, thus whenever you click them, the session changes, same as you have clicked a classical input type="submit". You may use a BUTTON type="button" element instead:

http://www.w3.org/TR/html4/interact/forms.html#h-17.5

or simply an image
Copy linkTweet thisAlerts:
@KirtanglauthorMar 11.2008 — Yeah, i remember the button tag trick, just like links, Add the <img> tage between the 2 <button> tags. legend, I also did the Background-color: transparent; and border: 0; to make it show only the image, nothing more.

I had to much trouble with the pause, but I relies its useless for what I want. I think I'm good to go. Thank you again.

Kirt
×

Success!

Help @Kirtangl spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...