JS Clock Text Input

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Art

    #1

    JS Clock Text Input

    Hi,

    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. What I would like
    to do now is prevent anything else happening when it's moused over. I
    was able to remove the cursor using the blur() method, something like
    this:

    document.formna me.inputname.bl ur();

    The cursor appears for about a second then disappears. However, it still
    activates. With WebTV I still get the yellow highlight around the input,
    I presume the pointer changes to the finger when using a PC.

    Is there a way to disable that with JavaScript, so that the input is
    simply a static element on the page ? There are the WebTV only
    attributes of "nohighligh t" 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.

    Thanks for any assistance.

    Later, Art.

  • Evertjan.

    #2
    Re: JS Clock Text Input

    Art wrote on 09 sep 2004 in comp.lang.javas cript:[color=blue]
    > I'm using a form text input to display a JavaScript clock.[/color]

    Why?

    An input is for inputting.

    Cann't you simply use a span or a div to display something?


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress,
    but let us keep the discussions in the newsgroup)

    Comment

    • Art

      #3
      Re: JS Clock Text Input

      Hi,

      I want the clock to be real time, second by second. I don't know that I
      can accomplish that with what you suggest.

      I did that with a document.write, however the clock did not increment
      second by second. It remained at the time it was when the page was
      entered/loaded.

      Thanks for your reply.

      Later, Art.

      Comment

      • Yann-Erwan Perio

        #4
        Re: JS Clock Text Input

        Art wrote:
        [color=blue]
        > 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.[/color]

        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["controlNam e"].value=
        new Date();
        },
        1000
        );
        [color=blue]
        > Is there a way to disable that with JavaScript, so that the input is
        > simply a static element on the page ?[/color]

        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/>
        [color=blue]
        > attributes of "nohighligh t" 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.[/color]

        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).
        [color=blue]
        > Thanks for any assistance.[/color]

        Even foolish one ? ;-)


        <script type="text/javascript">
        window.onload=f unction(evt){
        var h=new Function(""),f= document.forms[0].elements;
        for(var ii=0;ii<f.lengt h;ii++) { h=setWild(f[ii]); }
        document.onclic k=function() { h(); }
        setInterval(
        function(){
        for(var ii=0,dd=new Date();ii<f.len gth;ii++)
        f[ii].value=dd;
        },
        1000
        );
        }

        function setWild(el) {
        var m={x:0,y:0}, q, a=[], page, pos, dim, r=true, tgl;

        document.onmous emove=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.co mpatMode &&
        document.compat Mode.indexOf("C SS")!=-1 &&
        document.docume ntElement||docu ment.body;
        return {
        width:window.in nerWidth||doc&& doc.clientWidth ||0,
        height:window.i nnerHeight||doc &&doc.clientHei ght||0
        };
        }

        pos=function(el ){
        var p={x:0,y:0};
        do {
        p.x+=el.offsetL eft;
        p.y+=el.offsetT op;
        } while(el=el.off setParent);
        return p;
        }

        dim=function(el ){
        return {width:el.offse tWidth,height:e l.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+d m.width+100 &&
        m.y>ps.y-100&&m.y<ps.y+d m.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.a bs(M.random()*p g.height-dm.height))+"px ";
        }
        } else {
        r=false;
        break;
        }
        }
        if(r) setTimeout(argu ments.callee,42 );
        }

        return(q(),(set Wild=function(e l){return (a[a.length]=el,tgl);})(el) );
        }
        </script>

        <form>
        <input type="text" onfocus="this.b lur()" readonly="reado nly">
        <input type="text" onfocus="this.b lur()" readonly="reado nly">
        <input type="text" onfocus="this.b lur()" readonly="reado nly">
        </form>

        Comment

        • Joakim Braun

          #5
          Re: JS Clock Text Input

          "Art" <Wazcal@webtv.n et> skrev i meddelandet
          news:17409-4140AED0-225@storefull-3333.bay.webtv. net...[color=blue]
          > Hi,
          >
          > I want the clock to be real time, second by second. I don't know that I
          > can accomplish that with what you suggest.
          >
          > I did that with a document.write, however the clock did not increment
          > second by second. It remained at the time it was when the page was
          > entered/loaded.
          >
          > Thanks for your reply.
          >
          > Later, Art.[/color]

          Lookup the various DOM methods for manipulating text node content. That
          would let you update text "live" (without form elements) on compliant
          browsers.

          Joakim Braun


          Comment

          • Dr John Stockton

            #6
            Re: JS Clock Text Input

            JRS: In article <4140bcb3$0$327 31$626a14ce@new s.free.fr>, dated Thu, 9
            Sep 2004 22:26:50, seen in news:comp.lang. javascript, Yann-Erwan Perio
            <y-e.perio@em-lyon.com> posted :[color=blue]
            >Art wrote:
            >[color=green]
            >> 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.[/color][/color]

            Read the newsgroup FAQ, and find my js-date2.htm.

            It's rather pointless, except as a programming exercise. For date and
            time elsewhere, see my js-date5.htm.

            [color=blue]
            >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["controlNam e"].value=
            > new Date();
            > },
            > 1000
            >);[/color]

            That does not necessarily do every second. In Win98 it will miss about
            one in 20; in NT perhaps 1 in 100 or 200; the fix is easy enough. As
            above.

            --
            © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
            <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
            <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
            <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

            Comment

            Working...