liamloveslearning Posted May 24, 2011 Share Posted May 24, 2011 Hi all, im trying to set a variable using an if else statement only its breaking my entire code and not executing anything, Can anybody see why? function Calculate() { var ContentMinutes = document.getElementById ("ContentMinutes").value; var ContentMinutesSelect = document.getElementById('ContentMinutesDD').options[document.getElementById('ContentMinutesDD').selectedIndex].value var RenderingHours=20; if (ContentMinutesSelect == 0.0166) { var RenderingHours = 10; var VideoHours = 5; var VideoSeconds = 1; document.getElementById("RenderHours").innerHTML=RenderingHours; document.getElementById("VideoHours").innerHTML=VideoHours; document.getElementById("VideoSeconds").innerHTML=VideoSeconds; } else if (ContentMinutesSelect == 0.0003) { var RenderingHours = 1540; var VideoHours = 54; var VideoSeconds = 1; document.getElementById("RenderHours").innerHTML=RenderingHours; document.getElementById("VideoHours").innerHTML=VideoHours; document.getElementById("VideoSeconds").innerHTML=VideoSeconds; } else { var RenderingHours = 6410; var VideoHours = 345; var VideoSeconds = 124; document.getElementById("RenderHours").innerHTML=RenderingHours; document.getElementById("VideoHours").innerHTML=VideoHours; document.getElementById("VideoSeconds").innerHTML=VideoSeconds; } var NoOfFrames = document.getElementById ("NoOfFrames").value; //var EstimatedCoreHours = document.getElementById ("EstimatedCoreHours").value; var ServiceLevel = document.getElementById('SerivceLevelDD').options[document.getElementById('SerivceLevelDD').selectedIndex].value; var RenderHours = 1; var CoresInTest = document.getElementById ("CoresInTest").value; var EstimatedCoreHours = GetNumeric(NoOfFrames) * GetNumeric(RenderingHours) * GetNumeric(CoresInTest); var EstimatedTotal = GetNumeric(ServiceLevel) * GetNumeric(EstimatedCoreHours); alert('Estimated Cost' +EstimatedTotal); document.getElementById("EstimatedCoreHours").innerHTML=EstimatedCoreHours.toFixed(2); document.getElementById("EstimatedTotal").innerHTML=EstimatedTotal.toFixed(2); document.getElementById("EstimatedCoreHours").style.backgroundColor="yellow"; document.getElementById("EstimatedTotal").style.backgroundColor="yellow"; } function GetNumeric(val) { if (isNaN(parseFloat(val))) { return 0; } return parseFloat(val); } Quote Link to comment https://forums.phpfreaks.com/topic/237324-variable-if-else/ Share on other sites More sharing options...
trq Posted May 24, 2011 Share Posted May 24, 2011 'breaking my entire code' isn't exactly very descriptive, what debugging have you done? Quote Link to comment https://forums.phpfreaks.com/topic/237324-variable-if-else/#findComment-1219521 Share on other sites More sharing options...
KevinM1 Posted May 24, 2011 Share Posted May 24, 2011 Try using your GetNumeric function on ContentMinutesSelect, like you did for your other form values.... Quote Link to comment https://forums.phpfreaks.com/topic/237324-variable-if-else/#findComment-1219522 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.