I've found a simple script (at http://www.javascriptkit.com/script/script2/bodymass.shtml) that determines someone's BPI that I'm now trying to alter to fit my basketball workout program. Been trying all day, can't figure it out... If anyone can help, thanks a ton.

Their formula is as follows:

<FORM NAME="BMI" method=POST>
<TABLE border=1>
<TR>
<TD><DIV ALIGN=CENTER>Your Weight (kg)</DIV></TD>
<TD><DIV ALIGN=CENTER>Your Height (cm)</DIV></TD>
<TD><DIV ALIGN=CENTER>Your BMI</DIV></TD>
<TD><DIV ALIGN=CENTER>My Comment</DIV></TD>
</TR>

<TR>
<TD><INPUT TYPE=TEXT NAME=weight  SIZE=10 onFocus="this.form.weight.value=''"></TD>
<TD><INPUT TYPE=TEXT NAME=height  SIZE=10 onFocus="this.form.height.value=''"></TD>
<TD><INPUT TYPE=TEXT NAME=bmi     SIZE=8 ></TD>
<TD><INPUT TYPE=TEXT NAME=my_comment size=35></TD>
</TABLE>

<P>
<INPUT TYPE="button" VALUE="Let's see" onClick="computeform(this.form)">
<INPUT TYPE="reset"  VALUE="Reset" onClick="ClearForm(this.form)">
</FORM>






<SCRIPT LANGUAGE="JAVASCRIPT">
<!-- hide this script tag's contents from old browsers

//Body Mass calculator- by John Scott (johnscott03@yahoo.com)
//Visit JavaScript Kit (http://javascriptkit.com) for script
//Credit must stay intact for use

function ClearForm(form){

    form.weight.value = "";
    form.height.value = "";
    form.bmi.value = "";
    form.my_comment.value = "";

}

function bmi(weight, height) {

          bmindx=weight/eval(height*height);
          return bmindx;
}

function checkform(form) {

       if (form.weight.value==null||form.weight.value.length==0 || form.height.value==null||form.height.value.length==0){
            alert("\nPlease complete the form first");
            return false;
       }

       else if (parseFloat(form.height.value) <= 0||
                parseFloat(form.height.value) >=500||
                parseFloat(form.weight.value) <= 0||
                parseFloat(form.weight.value) >=500){
                alert("\nReally know what you're doing? \nPlease enter values again. \nWeight in kilos and \nheight in cm");
                ClearForm(form);
                return false;
       }
       return true;

}

function computeform(form) {

       if (checkform(form)) {

       yourbmi=Math.round(bmi(form.weight.value, form.height.value/100));
       form.bmi.value=yourbmi;

       if (yourbmi >40) {
          form.my_comment.value="You are grossly obese, consult your physician!";
       }

       else if (yourbmi >30 && yourbmi <=40) {
          form.my_comment.value="Umm... You are obese, want some liposuction?";
       }

       else if (yourbmi >27 && yourbmi <=30) {
          form.my_comment.value="You are very fat, do something before it's too late";
       }

       else if (yourbmi >22 && yourbmi <=27) {
          form.my_comment.value="You are fat, need dieting and exercise";
       }

       else if (yourbmi >=21 && yourbmi <=22) {
          form.my_comment.value="I envy you. Keep it up!!";
       }

       else if (yourbmi >=18 && yourbmi <21) {
          form.my_comment.value="You are thin, eat more.";
       }

       else if (yourbmi >=16 && yourbmi <18) {
          form.my_comment.value="You are starving. Go Find some food!";
       }

       else if (yourbmi <16) {
          form.my_comment.value="You're grossly undernourished, need hospitalization ";
       }

       }
       return;
}
 // -- done hiding from old browsers -->
</SCRIPT>

And I'm trying to alter their function
bmindx=weight/eval(height*height)

to have these variables instead:


XDrill (X1) =SUM(100-(25-X1)*5)/10
2ptrs (X2) =SUM(100-6.66667*(23-X2))/10
3ptrs (X3) =SUM(100-7.51*(15-X3))/10
Nash (X4) =SUM(100-4*(32-(X4)))/10

where...

(X1+X2+X3+X4)*2.5 = TOTAL SCORE


so that the end product is more like the following:

<FORM NAME="BMI" method=POST>
<TABLE border=1>
<TR>
<TD><DIV ALIGN=CENTER>X-Drill</DIV></TD>
<TD><DIV ALIGN=CENTER>3's</DIV></TD>
<TD><DIV ALIGN=CENTER>2's</DIV></TD>
<TD><DIV ALIGN=CENTER>Nash</DIV></TD>
<TD bgcolor="#000000"><DIV ALIGN=CENTER><font color="ffffff">Score</font></DIV></TD>
<TD><DIV ALIGN=CENTER>Comment</DIV></TD>
</TR>

<TR>
<TD><INPUT TYPE=TEXT NAME=weight  SIZE=4 onFocus="this.form.weight.value=''"></TD>
<TD><INPUT TYPE=TEXT NAME=height  SIZE=4 onFocus="this.form.height.value=''"></TD>
<TD><INPUT TYPE=TEXT NAME=bmi     SIZE=4 ></TD>
<TD><INPUT TYPE=TEXT NAME=bmi     SIZE=4 ></TD>
<TD bgcolor="#000000"><INPUT TYPE=TEXT NAME=bmi     SIZE=4 ></TD>
<TD><INPUT TYPE=TEXT NAME=my_comment size=60></TD>
</TABLE>

<P>
<INPUT TYPE="button" VALUE="Let's see" onClick="computeform(this.form)">
<INPUT TYPE="reset"  VALUE="Reset" onClick="ClearForm(this.form)">
</FORM>

The function computeform(form) and if (yourbmi >40) parts are easy enough, just everything else is bugging me so much! Any help would be greatly appreciated. Thanks again!

Let me know if I'm close. I've got the formula to compute the desired value, but now I'm trying to figure out how to get the corresponding text to appear and how to round the value to 4 decimal places or less.

Here's my latest code. ALMOST DONE??????

<html> 
<head> 
<title>Input tutorial</title> 
<script language="javascript"> 
function addNumbers() 
{ 
var val1 = parseInt(document.getElementById("value1").value); 
var val2 = parseInt(document.getElementById("value2").value); 
var val3 = parseInt(document.getElementById("value3").value); 
var val4 = parseInt(document.getElementById("value4").value); 
var ansD = document.getElementById("answer"); 
ansD.value = (100-(25-val1)*5)/4 + (100-6.66667*(23-val2))/4 + (100-7.51*(15-val3))/4 + (100-4*(32-(val4)))/4 ; 
 }





function checkform(form) {
 
       if (value1==null||value1.length==0 || value2==null||value2.length==0 || value3==null||value3.length==0 || value4==null||value4.length==0){
            alert("\nPlease complete the form first");
            return false;
       }
 
       else if (parseFloat(value1) < 0||
                parseFloat(value1) >=40||
                parseFloat(value2) < 0||
                parseFloat(value2) >=40)
                parseFloat(value3) < 0||
                parseFloat(value3) >=40||
                parseFloat(value4) <= 0||
                parseFloat(value4) >=31){
                alert("\nDo you know what you're doing? \nPlease enter your scores again.");
                ClearForm(form);
                return false;
       }
       return true;
 
}
 
function computeform(form) {
 
     
 
       if (answer >90) {
          form.my_comment.value="Amazing Job!!";
       }
 
       else if (answer >80 && yourbmi <=90) {
          form.my_comment.value="You're doing very well.";
       }
 
       else if (answer >65 && yourbmi <=80) {
          form.my_comment.value="Keep up the great work";
       }
 
       else if (answer >50 && yourbmi <=65) {
          form.my_comment.value="You need to push it a little harder";
       }
 
       else if (answer >=35 && yourbmi <=50) {
          form.my_comment.value="You can do better than that!";
       }
 
       else if (answer >=20 && yourbmi <35) {
          form.my_comment.value="Poor performance";
       }
 
       else if (answer >=10 && yourbmi <20) {
          form.my_comment.value="You must try harder than that";
       }
 
       else if (answer <10) {
          form.my_comment.value="You're definitely not giving it all your effort ";
       }
 
       }
       return;
}
</SCRIPT>


</head> 
<body> 
XDrill = <input type="text" id="value1" name="value1" value="" SIZE=4 /> 
2ptrs = <input type="text" id="value2" name="value2" value="" SIZE=4/> 
3ptrs = <input type="text" id="value3" name="value3" value="" SIZE=4/> 
Nash = <input type="text" id="value4" name="value4" value="" SIZE=4/>
<input type="button" name="Sumbit" value="Click here" onclick="javascript:addNumbers()"/> 
<br><br>Score = <input type="text" id="answer" name="answer" value=""/ SIZE=4> 
</body> 
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.