I tried the following ways of calculation and passing back to the form I made. The commented out function is the same, but handled differently and was my first attempt.

function oneRepCal(wt,rp) {
    this.wt = parseFloat(document.ormCalc.wLift.value);
    this.rp = parseFloat(document.ormCalc.rComp.value);
    lifted = this.wt * this.rp;
    oneRepC = (lifted * .03333) + this.wt;

    document.ormCalc.oneRep.value = oneRepC;
    document.ormCalc.nine5.value = Math.round(oneRepC * .95);
    document.ormCalc.ninety.value = Math.round(oneRepC * .9);
    document.ormCalc.eight5.value = Math.round(oneRepC * .85);
    document.ormCalc.eighty.value = Math.round(oneRepC * .8);
    document.ormCalc.seven5.value = Math.round(oneRepC * .75);
    document.ormCalc.seventy.value = Math.round(oneRepC * .7);
    document.ormCalc.six5.value = Math.round(oneRepC * .65);
    document.ormCalc.sixty.value = Math.round(oneRepC * .6);
    document.ormCalc.five5.value = Math.round(oneRepC * .55);
    document.ormCalc.fifty.value = Math.round(oneRepC * .5);
}

/*
function oneRepCal() {
    var weight = parseFloat(document.ormCalc.wLift.value);
    var reps = parseFloat(document.ormCalc.rComp.value);
    var lifted = (weight * reps * .03333) + weight;

    if ((weight == 0) || (reps == 0) || (weight == '') || (reps == '') || isNaN(weight) || isNaN(reps)) {
        alert("Enter your numbers!");
        return false;
    }

    document.ormCalc.oneRep.value = lifted;
    document.ormCalc.nine5.value = Math.round(lifted * .95);
    document.ormCalc.ninety.value = Math.round(lifted * .9);
    document.ormCalc.eight5.value = Math.round(lifted * .85);
    document.ormCalc.eighty.value = Math.round(lifted * .8);
    document.ormCalc.seven5.value = Math.round(lifted * .75);
    document.ormCalc.seventy.value = Math.round(lifted * .7);
    document.ormCalc.six5.value = Math.round(lifted * .65);
    document.ormCalc.sixty.value = Math.round(lifted * .6);
    document.ormCalc.five5.value = Math.round(lifted * .55);
    document.ormCalc.fifty.value = Math.round(lifted * .5);

}
*/

All I'm getting are the values passing to the address bar, quickly filling the text inputs, then the text inputs auto-clearing. The form I'm working with is below:

<form name="ormCalc" id="ormCalc">
<table>
<caption>One Rep Max Calculator</caption>
<tr>
    <th colspan="6" id="subTitle">Approx. in Pounds (5/3/1 Method close to Epley Method)</th>
</tr>
<tr>
    <td class="main-left-side">Weight Lifted:</td>
    <td class="right-side"><input type="text" name="wLift" class="formInput" id="wLift"></td>
    <td class="left-side">95% 1RM:</td>
    <td class="right-side"><input type="text" name="nine5" class="formInput"></td>
    <td class="left-side">70% 1RM:</td>
    <td class="right-side"><input type="text" name="seventy" class="formInput"></td>
</tr>
<tr>
    <td class="main-left-side">Reps Completed:</td>
    <td class="right-side"><input type="text" name="rComp" class="formInput" id="rComp"></td>
    <td class="left-side">90% 1RM:</td>
    <td class="right-side"><input type="text" name="ninety" class="formInput"></td>
    <td class="left-side">65% 1RM:</td>
    <td class="right-side"><input type="text" name="six5" class="formInput"></td>
</tr>
<tr>
    <td class="main-left-side"></td>
    <td class="right-side"></td>
    <td class="left-side">85% 1RM:</td>
    <td class="right-side"><input type="text" name="eight5" class="formInput"></td>
    <td class="left-side">60% 1RM:</td>
    <td class="right-side"><input type="text" name="sixty" class="formInput"></td>
</tr>
<tr>
    <td class="main-left-side"></td>
    <td class="right-side"></td>
    <td class="left-side">80% 1RM</td>
    <td class="right-side"><input type="text" name="eighty" class="formInput"></td>
    <td class="left-side">55% 1RM</td>
    <td class="right-side"><input type="text" name="five5" class="formInput"></td>
</tr>
<tr>
    <td class="main-left-side">One Rep Max:</td>
    <td class="right-side"><input type="text" name="oneRep" class="formInput"></td>
    <td class="left-side">75% 1RM:</td>
    <td class="right-side"><input type="text" name="seven5" class="formInput"></td>
    <td class="left-side">50% 1RM:</td>
    <td class="right-side"><input type="text" name="fifty" class="formInput"></td>
</tr>
</table>
<input type="submit" value="Calculate" onClick="oneRepCal()">
</form>

Where am I going wrong?

Recommended Answers

All 2 Replies

Member Avatar for diafol

The form is being submitted by the looks of it. You need to prevent the default action of the submit button click event.

An example:

<input type="submit" value="Calculate" id="mySubmit">


document.getElementById("mySubmit").addEventListener("click", function(event){
    event.preventDefault();
    oneRepCal();
});

I changed it from a "submit" button to a regular button and that fixed everything. Thank you so much!

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.