I need to create an "if statement" for the below result of a javascript calculation, however the "var ansD" variable won`t let me, any help would be appreciated,
It is the below line in question, i have seperated it out in the script for easier viewing,
Code:var ansD = document.getElementById("result_price"); ansD.value = '' + Math.round ((val1 * val2 * val3*100/5000/100 + 15.00 * 1.50 +(val4 * 0.68))*(valq1))Any help would be much appreciated,Code:<script type="text/javascript"> var btn = document.getElementById('calculate'); btn.onclick = function() { // get the input values var val1 = parseInt(document.getElementById('val1').value); var val2 = parseInt(document.getElementById('val2').value); var val3 = parseInt(document.getElementById('val3').value); var val4 = parseInt(document.getElementById('val4').value); var valq1 = parseInt(document.getElementById('valq1').value); var valq1a = parseInt(document.getElementById('valq1a').value); var val1a = parseInt(document.getElementById('val1a').value); var val2a = parseInt(document.getElementById('val2a').value); var val3a = parseInt(document.getElementById('val3a').value); var val4a = parseInt(document.getElementById('val4a').value); var ansD = document.getElementById("answer"); ansD.value = (val4 + val4a) * (valq1); var ansD = document.getElementById("answer2"); ansD.value = '' + Math.round((valq1) * val1 * val2 * val3*100/5000/100 + val1a * val2a * val3a * 100/5000/100); var ansD = document.getElementById("answer3"); ansD.value = '' + Math.round((valq1) * val1 * val2 * val3*100/1000000/100 + val1a * val2a * val3a*100/1000000/100); var ansD = document.getElementById("answer4"); ansD.value = '' + Math.round((valq1) * val1 * val2 * val3*100/1000000*35.31/100 + val1a * val2a * val3a*100/1000000*35.31/100); var ansD = document.getElementById("result_price"); ansD.value = '' + Math.round ((val1 * val2 * val3*100/5000/100 + 15.00 * 1.50 +(val4 * 0.68))*(valq1)) var ansD = document.getElementById("result_pricea"); ansD.value = '' + Math.round ((val1a * val2a * val3a*100/5000/100 + 15.00 *1.50 +(val4a * 0.68))*(valq1a)) var result_price = parseInt(document.getElementById("result_price").value); var result_pricea = parseInt(document.getElementById("result_pricea").value); var ansD = document.getElementById("answer5"); ansD.value =result_price + result_pricea; // get the elements to hold the results var result1a = document.getElementById('result1a') var result1 = document.getElementById('result1') var result2 = document.getElementById('result2'); var result3 = document.getElementById('result3'); var tot_result3 = document.getElementById('tot_result3'); var result1a = document.getElementById('result1a') var result2a = document.getElementById('result2a'); var result3a = document.getElementById('result3a'); var tot_result3 = document.getElementById('tot_result3'); var val1a = parseInt(document.getElementById('val1a').value); var val2a = parseInt(document.getElementById('val2a').value); var val3a = parseInt(document.getElementById('val3a').value); var val4a = parseInt(document.getElementById('val4a').value); // get the elements to hold the results // create an empty array to hold error messages var msg = []; // check each input value, and add an error message // to the array if it's not a number if (isNaN(val1)) { msg.push('Height is not a number'); } if (isNaN(val2)) { msg.push('Width is not a number'); } if (isNaN(val3)) { msg.push('Length is not a number'); } if (isNaN(val1a)) { msg.push('Height is not a number'); } if (isNaN(val2a)) { msg.push('Width is not a number'); } if (isNaN(val3a)) { msg.push('Length is not a number'); } // if the array contains any values, display the error message(s) // as a comma-separated string in the first <span> element if (msg.length > 0) { result1.innerHTML = msg.join(', '); } else if (msg.length > 0) { result1a.innerHTML = msg.join(', '); } else { // otherwise display the results in the <span> elements result1.innerHTML = '' + Math.round((val1 * val2 * val3*100)/5000)/100; result1a.innerHTML = '' + Math.round((val1a * val2a * val3a*100)/5000)/100; result5.innerHTML = '' + Math.round((val1 * val2 * val3*100)/1000000)/100; result5a.innerHTML = '' + Math.round((val1a * val2a * val3a*100)/1000000)/100; result6.innerHTML = '' + Math.round((val1 * val2 * val3*100)/1000000*35.31)/100; result6a.innerHTML = '' + Math.round((val1a * val2a * val3a*100)/1000000*35.31)/100; //START TEST LINE //END TEST LINE // calculations for first line on form { var x=""; if (+ val1 * val2 * val3/ 5000 <70) { x="OK"; } else { x="X"; } document.getElementById("result_volweight").innerHTML=x; } result2.innerHTML = '' + (2*val1 + 2*val2 + val3); { var x=""; if (2*val1 + 2*val2 + val3 <419) { x="OK"; } else { x="X"; } document.getElementById("result_girth").innerHTML=x; } result3.innerHTML = '' + (val4); { var x=""; if (val4 <70) { x="OK"; } else { x="X"; } document.getElementById("result_actual_weight").innerHTML=x; } if (+ val1 * val2 * val3/ 5000 >69) { alert("Line 1 - The Volumetric Weight Exceeds The Limits For Standard Parcel Delivery - Please Contact Us For Alternative Delivery Options"); return false; } if (val4 >69) { alert("Line 1 - The Actual Weight Exceeds The Limits For Standard Parcel Delivery - Please Contact Us For Alternative Delivery Options"); return false; } else if (2*val1 + 2*val2 + val3 >419) { alert("Line 1 - The Girth + Length Exceeds The Limits For Standard Parcel Delivery - Please Contact Us For Alternative Delivery Options"); return false; } else if (val3>270) { alert("Line 1 - Length Exceeds The Limits For Standard Parcel Delivery - Please Contact Us For Alternative Delivery Options"); return false; } //1st line of form end //calculations for 2nd line of form { var x=""; if (+ val1a * val2a * val3a/ 5000 <70) { x="OK"; } else { x="X"; } document.getElementById("result_volweighta").innerHTML=x; } result2a.innerHTML = '' + (2*val1a + 2*val2a + val3a); { var x=""; if (2*val1a + 2*val2a + val3a <419) { x="OK"; } else { x="X"; } document.getElementById("result_girtha").innerHTML=x; } result3a.innerHTML = '' + (val4a); { var x=""; if (val4a<70) { x="OK"; } else { x="X"; } document.getElementById("result_actual_weighta").innerHTML=x; } if (+ val1a * val2a * val3a/ 5000 >69) { alert("Line 2 - The Volumetric Weight Exceeds The Limits For Standard Parcel Delivery - Please Contact Us For Alternative Delivery Options"); return false; } if (val4a >69) { alert("Line 2 - The Actual Weight Exceeds The Limits For Standard Parcel Delivery - Please Contact Us For Alternative Delivery Options"); return false; } else if (2*val1a + 2*val2a + val3a >419) { alert("Line 2 - The Girth + Length Exceeds The Limits For Standard Parcel Delivery - Please Contact Us For Alternative Delivery Options"); return false; } else if (val3a>270) { alert("Line 2 - Length Exceeds The Limits For Standard Parcel Delivery - Please Contact Us For Alternative Delivery Options"); return false; } //2nd line of form end } }; </script>
Regards,
LightBulb



Reply With Quote


Bookmarks