tutorial function error

Discussion in 'HTML' started by DEEP 3z, Nov 17, 2003.

  1. DEEP 3z

    DEEP 3z Guest

    Im currently learning JavaScript and im doing a tutorial from a magazine....
    which doesnt work :/
    Through elimination this is the code thats causing a problem... apparently
    the browser is expecting a ; somewhere

    funtion myupdate()
    {
    setTimeout("myupdate();" ,100);
    if(mystate=="start")
    {
    mynow = new Date();
    mywatch = mynow.getTime() - mystarted.getTime();
    document.myform.mytime.value = mywatch/1000;
    }
    }

    This is being called during onLoad as follows:
    <BODY onLoad="myreset(); myupdate();">

    If i remove the myupdate funtion declaration and call all works fine.
    Any ideas?
    Thanks
     
    DEEP 3z, Nov 17, 2003
    #1
    1. Advertising

  2. DEEP 3z wrote:

    > This is being called during onLoad as follows:
    > <BODY onLoad="myreset(); myupdate();">


    Where is the code for myreset?

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me - http://www.goddamn.co.uk/tobyink/?page=132
     
    Toby A Inkster, Nov 17, 2003
    #2
    1. Advertising

  3. DEEP 3z

    DEEP 3z Guest

    Heres the body section in full, might be an issue with myreset but i dont
    get that impression

    <BODY onLoad="myreset(); myupdate();">
    <SCRIPT>
    function myreset() {
    mystate = "stop";
    mywatch = 0;
    document.myform.mytime.value = mywatch/1000;
    }

    function mystartstop() {
    if (mystate == "stop") {
    mystate = "start";
    mystarted = new Date();
    mystarted.setTime(mystarted.getTime() - mywatch);
    } else {
    mystate = "stop";
    mystopped = new Date();
    mywatch = mystopped.getTime() - mystarted.getTime();
    document.myform.mytime.value = mywatch/1000;}
    }

    function myupdate() {
    setTimeout("myupdate();", 100);
    if (mystate == "start"){
    mynow = new Date();
    mywatch = mynow.getTime() - mystarted.getTime();
    document.myform.mytime.value = mywatch/1000;}
    }
    </SCRIPT>

    <CENTER>
    <FORM NAME="myform">
    Time:<INPUT TYPE="TEXT" Name="mytime">
    <INPUT TYPE="BUTTON" VALUE="Start/Stop" onClick="mystartstop()">
    <INPUT TYPE="BUTTON" VALUE="Reset" onClick="myreset()">
    </FORM>
    </CENTER>
    </BODY>
     
    DEEP 3z, Nov 17, 2003
    #3
  4. DEEP 3z

    rf Guest

    "DEEP 3z" <> wrote in message
    news:A7dub.6642$...
    > Heres the body section in full, might be an issue with myreset but i dont
    > get that impression
    >

    <snip code>

    Works fine for me.

    Cheers
    Richard.
     
    rf, Nov 18, 2003
    #4
  5. rf wrote:

    > "DEEP 3z" <> wrote in message
    > news:A7dub.6642$...
    >> Heres the body section in full, might be an issue with myreset but i dont
    >> get that impression

    >
    > <snip code>
    >
    > Works fine for me.


    Ditto. Tested in IE6, NN4.8, Mozilla 1.4 and Opera 7.21.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me - http://www.goddamn.co.uk/tobyink/?page=132
     
    Toby A Inkster, Nov 18, 2003
    #5
  6. DEEP 3z

    DEEP 3z Guest

    Weird its working for me now, I thought it should have in the 1st place, I
    must have made an error in copying it (i tried creating it bit by bit to
    build understanding) but im sure i copied and pasted at one point as i did
    for the newsgroup.

    Anyway apologetic thanks for your slightly wasted time all :/
     
    DEEP 3z, Nov 18, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rensjuh
    Replies:
    7
    Views:
    984
    Mabden
    Sep 2, 2004
  2. Lee Fleming
    Replies:
    49
    Views:
    801
    Steve Holden
    Aug 14, 2007
  3. W. Watson
    Replies:
    13
    Views:
    1,073
    W. Watson
    Sep 20, 2007
  4. Linuxmank
    Replies:
    36
    Views:
    1,504
    Linuxmank
    Aug 8, 2009
  5. Replies:
    3
    Views:
    182
    Curt Hibbs
    Feb 6, 2006
Loading...

Share This Page