I need help on a code that wont calculate for a bmi calculator for some reason it just wont show results when I click on calculate. Also I want the reverse bmi calculator to grab height and weight from the first calculator, I will put all codes pasted below. Thank you in advance for your help.
I need help on a code that wont calculate for a bmi calculator for some reason it just wont show results when I click on calculate. Also I want the reverse bmi calculator to grab height and weight from the first calculator, I will put all codes pasted below. Thank you in advance for your help.
--snip---
---javascript---
function valButton(btn) {var cnt = -1;for (var i=btn.length-1; i > -1; i--) { if (btn[i].checked) {cnt = i; i = -1;}}if (cnt > -1) return btn[cnt].value;else return null;}function stripBlanks(fld) {var result = "";var c = 0;for (i=0; i < fld.length; i++) {if (fld.charAt(i) != " " || c > 0) {result += fld.charAt(i);if (fld.charAt(i) != " ") c = result.length;}}return result.substr(0,c);}function calc(thisform) {var d = valButton(thisform.d);
....
Properly formatted code is a big help when debugging, one statement per line and statements under control of if, else, for, while, etc. are indented. Comments don't hurt either, especially when asking for other eyes to check out your code.
Code:
function stripBlanks(fld) {
var result = "";
var c = 0;
for (i=0; i < fld.length; i++) {
if (fld.charAt(i) != " " || c > 0) {
result += fld.charAt(i);
if (fld.charAt(i) != " ")
c = result.length; }
}
return result.substr(0,c);
}
Bookmarks