merlyn
01-06-2005, 07:08 PM
Basically this code seems to halt after calculation of the total fat and needs to have 'TotalFat' defined. Im still working on this however would like to hear opinions to a solution. Yes I am very new to Javascript, lol.
<script LANGUAGE="JAVASCRIPT">
<!--Hide from old browsers
function FatCal(myform) {
var FatGrams=document.Fat.Grams.value
var FatGrams=parseInt(FatGrams,10)
if (isNaN(FatGrams)) {
alert("Please enter the fat grams.")
document.Fat.Grams.value=" "
document.Fat.Grams.focus()
}
else {
alert("FatCal Elsestart")
var FatNumbCal=document.Fat.NumbCal.value
var FatNumbCal=parseInt(FatNumbCal,10)
alert("FatCal Elsestart2")
if (isNaN(FatNumbCal)) {
alert("Please enter the total calories")
document.Fat.NumbCal.value=""
document.Fat.NumbCal.focus()
alert("FatCal ElseEnd")
}
}
// calculate fat calories
var TotalFat = FatGrams
var TotalFatCal = FatGrams * 9
document.Fat.Total.value = TotalFatCal
// calculate percentage of fat
var TotalFatPerc = TotalFat/FatNumbCal
var TotalFatPerc = new String(TotalFatPerc)
document.Fat.FatPerc.value = makePerc(TotalFatPerc)
alert("FatCal end")
}
// Start makePerc function here
function makePerc(TotalFatPerc) {
alert("makePerc start")
var valuein = TotalFatPerc
strPercent = ""
tPercent = valuein
decimal = tPercent.indexOf(".")
Percent = parseInt(tPercent.substring(decimal+1,decimal+3),10)
return strPercent
alert("makePerc end")
}
//-->
</script>
<script LANGUAGE="JAVASCRIPT">
<!--Hide from old browsers
function FatCal(myform) {
var FatGrams=document.Fat.Grams.value
var FatGrams=parseInt(FatGrams,10)
if (isNaN(FatGrams)) {
alert("Please enter the fat grams.")
document.Fat.Grams.value=" "
document.Fat.Grams.focus()
}
else {
alert("FatCal Elsestart")
var FatNumbCal=document.Fat.NumbCal.value
var FatNumbCal=parseInt(FatNumbCal,10)
alert("FatCal Elsestart2")
if (isNaN(FatNumbCal)) {
alert("Please enter the total calories")
document.Fat.NumbCal.value=""
document.Fat.NumbCal.focus()
alert("FatCal ElseEnd")
}
}
// calculate fat calories
var TotalFat = FatGrams
var TotalFatCal = FatGrams * 9
document.Fat.Total.value = TotalFatCal
// calculate percentage of fat
var TotalFatPerc = TotalFat/FatNumbCal
var TotalFatPerc = new String(TotalFatPerc)
document.Fat.FatPerc.value = makePerc(TotalFatPerc)
alert("FatCal end")
}
// Start makePerc function here
function makePerc(TotalFatPerc) {
alert("makePerc start")
var valuein = TotalFatPerc
strPercent = ""
tPercent = valuein
decimal = tPercent.indexOf(".")
Percent = parseInt(tPercent.substring(decimal+1,decimal+3),10)
return strPercent
alert("makePerc end")
}
//-->
</script>