Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: while loop

  1. #1
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    while loop

    i have created a while loop for some error checking in a clocking system... it's supposed to check the time sort of making sure 1 record is greater than another...

    ie. reach office 08:00
    lunch break 12:00
    back from break 13:00
    off work 18:00

    somehow my code only works sometimes... and if it's only a few minutes difference it doesn't detect it... can someone help?


    Code:
    var a=0
    var b =1
    var count=0
    while (count<=20)
    {
    var sClockin  = document.Report.txtClockTime(a).value
    var sClockout  = document.Report.txtClockTime(b).value
    		
    sClockin = sClockin.replace(/:/gi,"");
    sClockout = sClockout.replace(/:/gi,"");
    		
    if (parseInt(sClockout) < parseInt(sClockin))
    {
    alert ("Clock-Out time must be greater than or equal to Clock-In time");
    return false;
    }
    if(a > 0 && b > 1)
    {
    if(parseInt(sClockin) < parseInt(sClockout))
    {
    alert("Latest Clock-In time must be greater than last Clock-Out time");
    return false;
    }
    }
    a=a+2;
    b=b+2;
    count++
    }
    }

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    maybe:
    var sClockin = document.Report.txtClockTime[a].value
    var sClockout = document.Report.txtClockTime[b].value
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmm doesnt seem to make any difference ?

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    For silly IE it does not, but Mozilla will tell you that document.Report.txtClockTime(a) is not a function... The index of an array's element must be inserted in square brackets, that's the correct syntax

    Now on the other hand your problem is that u have used parseInt() without specify the base (or you could have used Number() instead).

    You see, in fact parseInt() method is used to transform a number from a base (up to 36) to the decimal base. If you don't specify which is the base, you might get apparently phoney results:

    parseInt('0124') // will return 84, because the interpretor thinks '0124' as an octal number (base 8), not a decimal one

    parseInt('0124',10) //will return the correct decimal 124

    Or, as I said, you may also use Number('0124'), instead of parseInt()
    Last edited by Kor; 06-28-2006 at 11:10 AM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i tried all that and it's still the same... and when i tried on mozilla it's worse... it doesnt detect any eror at all....

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Should work... May I see the whole page? (or a link or an attachment)
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #7
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this is the attachment. i know there are errors here and there but this is confusing me ):

    editUserClock.txt


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •