...

View Full Version : while loop



aicirt
06-28-2006, 03: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;
}
}
a=a+2;
b=b+2;
count++
}
}

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

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

Kor
06-28-2006, 10: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()

aicirt
06-29-2006, 03: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:

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

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

4607



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum