View Full Version : while loop

06-28-2006, 04:20 AM
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?

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;

06-28-2006, 09:29 AM
var sClockin = document.Report.txtClockTime[a].value
var sClockout = document.Report.txtClockTime[b].value

06-28-2006, 09:49 AM
hmm doesnt seem to make any difference ?

06-28-2006, 11:07 AM
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()

06-29-2006, 04:09 AM
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.... :confused:

06-29-2006, 11:10 AM
Should work... May I see the whole page? (or a link or an attachment)

07-03-2006, 06:15 AM
this is the attachment. i know there are errors here and there but this is confusing me ):


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum