Files
What_Are_You_Lifting_App/js/-Old/Weight Calculation Script-Edited-Jquery.txt
2018-10-05 15:07:39 -04:00

196 lines
5.2 KiB
Plaintext

<script>
var weighttolift = 0;
var percentage = 0;
var target = 0;
// calculation function starts here
function startcalc() {
// making variables to use the values later.
// make the weight that have to be lifted after minus the bar weight etc.
var weighttolift = jQuery(".input-weight").val();
var weighttolift = jQuery("input[name=Weight]").val();
var percentage = jQuery("input[name=Percentage]").val();
var bar = jQuery(".input-bar").val();
var bar = jQuery("input[name=Bar]").val();
// targeted values
var target = ("input[name=Target]").val();
// this funciton calculates the weight percentage , final , difference etc
targets = Math.floor(weighttolift * percentage);
// final wieght calculater
target.value = targets;
var finals = Math.floor(parseInt(target.value) - parseInt(bar));
//this function assign the required plate pairs value
var weightcalculate = 0;
var avail45 = document.getElementById('avail45').value;
if (avail45 == 0) {
document.getElementById('req45').value = null;
} else {
//counts the required plates
var c = 0;
for (var a = 1; a <= avail45; a++) {
if (finals >= 90) {
c++;
finals -= 90;
weightcalculate += 90;
}
}
if (c == 0) {
document.getElementById('req45').value = null;
} else {
document.getElementById('req45').value = c;
}
}
var avail35 = document.getElementById('avail35').value;
if (avail35 == 0) {
document.getElementById('req35').value = null;
} else {
//counts the required plates
var d = 0;
for (var a = 1; a <= avail35; a++) {
if (finals >= 70) {
d++;
finals -= 70;
weightcalculate += 70;
}
}
if (d == 0) {
document.getElementById('req35').value = null;
} else {
document.getElementById('req35').value = d;
}
}
var avail25 = document.getElementById('avail25').value;
if (avail25 == 0) {
document.getElementById('req25').value = null;
} else {
//counts the required plates
var e = 0;
for (var a = 1; a <= avail25; a++) {
if (finals >= 50) {
e++;
finals -= 50;
weightcalculate += 50;
}
}
if (e == 0) {
document.getElementById('req25').value = null;
} else {
document.getElementById('req25').value = e;
}
}
var avail10 = document.getElementById('avail10').value;
if (avail10 == 0) {
document.getElementById('req10').value = null;
} else {
//counts the required plates
var f = 0;
for (var a = 1; a <= avail10; a++) {
if (finals >= 20) {
f++;
finals -= 20;
weightcalculate += 20;
}
}
if (f == 0)
{
document.getElementById('req10').value = null;
} else {
document.getElementById('req10').value = f;
}
}
var avail5 = document.getElementById('avail5').value;
if (avail5 == 0) {
document.getElementById('req5').value = null;
} else {
//counts the required plates
var g = 0;
for (var a = 1; a <= avail5; a++) {
if (finals >= 10) {
g++;
finals -= 10;
weightcalculate += 10;
}
}
if (g == 0) {
document.getElementById('req5').value = null;
} else {
document.getElementById('req5').value = g;
}
}
var avail2 = document.getElementById('avail2').value;
if (avail2 == 0) {
document.getElementById('req2').value = null;
} else {
//counts the required plates
var h = 0;
for (var a = 1; a <= avail2; a++) {
if (finals >= 5) {
h++;
finals -= 5;
weightcalculate += 5;
}
}
if (h == 0) {
document.getElementById('req2').value = null;
}
else {
document.getElementById('req2').value = h;
}
}
var bar2 = document.getElementById('Bar').value;
document.getElementById('finalw').value = Math.floor(parseInt(weightcalculate) + parseInt(bar2));
var targ = document.getElementById('Target').value;
var finalssweight = document.getElementById('finalw').value;
document.getElementById('diff').value = Math.floor(parseInt(targ) - parseInt(finalssweight));
}
</script>