Art wrote:
I'm using a form text input to display a JavaScript clock. It has no
other purpose than that, just show the date and time.
To change the time every second, use setInterval and reset the value of
the control at each interval with the new date's value.
setInterval(
function(){
document.forms[0].elements["controlName"].value=
new Date();
},
1000
);
Is there a way to disable that with JavaScript, so that the input is
simply a static element on the page ?
Evertjan suggestion's might do the job, check the FAQ for DynWrite for a
way to change a text value other than in a form control:
<URL:http://jibbering.com/faq/>
attributes of "nohighlight" and "noactivate' which I don't want to use
as they are not part of any specification and probably have no effect
for PC users.
Well yes, but other hosts may perform other specific actions, you simply
have no way to prevent all of these (all the more there are 100+
browsers available).
Thanks for any assistance.
Even foolish one ? ;-)
<script type="text/javascript">
window.onload=function(evt){
var h=new Function(""),f=document.forms[0].elements;
for(var ii=0;ii<f.length;ii++) { h=setWild(f[ii]); }
document.onclick=function() { h(); }
setInterval(
function(){
for(var ii=0,dd=new Date();ii<f.length;ii++)
f[ii].value=dd;
},
1000
);
}
function setWild(el) {
var m={x:0,y:0}, q, a=[], page, pos, dim, r=true, tgl;
document.onmousemove=function(evt){
evt=evt||window.event;
m.x=evt.clientX||evt.pageX||0;
m.y=evt.clientY||evt.pageY||0;
}
page=function(){
var doc=document.compatMode &&
document.compatMode.indexOf("CSS")!=-1 &&
document.documentElement||document.body;
return {
width:window.innerWidth||doc&&doc.clientWidth||0,
height:window.innerHeight||doc&&doc.clientHeight|| 0
};
}
pos=function(el){
var p={x:0,y:0};
do {
p.x+=el.offsetLeft;
p.y+=el.offsetTop;
} while(el=el.offsetParent);
return p;
}
dim=function(el){
return {width:el.offsetWidth,height:el.offsetHeight};
}
tgl=function(){
if((r=!r)) q();
}
q=function() {
for(var ii=0,pg=page(),ps,dm,M=Math;ii<a.length;ii++){
ps=pos(a[ii]);
dm=dim(a[ii]);
if(!isNaN(ps.x)) {
if(m.x>ps.x-100&&m.x<ps.x+dm.width+100 &&
m.y>ps.y-100&&m.y<ps.y+dm.height+100){
a[ii].style.position="absolute";
a[ii].style.left=(M.abs(M.random()*pg.width-dm.width))+"px";
a[ii].style.top=(M.abs(M.random()*pg.height-dm.height))+"px";
}
} else {
r=false;
break;
}
}
if(r) setTimeout(arguments.callee,42);
}
return(q(),(setWild=function(el){return (a[a.length]=el,tgl);})(el));
}
</script>
<form>
<input type="text" onfocus="this.blur()" readonly="readonly">
<input type="text" onfocus="this.blur()" readonly="readonly">
<input type="text" onfocus="this.blur()" readonly="readonly">
</form>