only My site

Saturday, June 21, 2008

Javascript : Using Math functions

function Multiply()
{//No of Hrs / No. of retry = Retry frequency
//Eg: 39 / 10 = 3.9 which is equal to 4 Hrs and 30 Mins
var var1,var2,var3;
var intHrs;
var intMins;
var1 = parseFloat(document.getElementById("txtop1").value );
var2 = parseFloat(document.getElementById("txtop2").value);
if ( isNaN(var1) isNaN(var2) )
{
var3 = 0;
document.getElementById("txtop3").value = "0:00" ;

return true;
}
var3 = var2 / var1;
intHrs = Math.floor(var3);
if (var3 - intHrs > 0.59)
{
intMins = (var3 - intHrs) - 0.60;
intHrs += 1;
}
else
{
intMins = var3 - intHrs;
}
intMins = intMins.toFixed(2) * 100;
document.getElementById("txtop3").value = intHrs + ":" + intMins ;
return true;
}



No comments: