Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
156
rated 0 times [  158] [ 2]  / answers: 1 / hits: 19249  / 12 Years ago, wed, december 5, 2012, 12:00:00

I'm making a BMI calculator (see JSFiddle - http://jsfiddle.net/b5ww2/) and I want the height in inches to display in feet and inches. I also want the weight in pounds to be displayed in stones and pounds.



This is the code I'm using to convert the slider value to cm and inches:



slide: function( event, ui ) {
$( #heightslidecm ).html( ui.value + 'cm' );
$( #heightslidein ).html( (ui.value*0.393700787).toFixed(0) + 'in' );
}


My js knowledge isn't great - especially when it comes to the math aspect.



Any ideas?



Thanks in advance


More From » jquery

 Answers
10

You simply need to include the logic for the conversion. Here is an example for feet and inches:



slide: function( event, ui ) {
$( #heightslidecm ).html( ui.value + 'cm' );

var inches = (ui.value*0.393700787).toFixed(0);
var feet = Math.floor(inches / 12);
inches %= 12;

$( #heightslidein ).html( feet + ft + inches + 'in');
}


You just need to repeat this same logic for the pounds/stone using the appropriate conversion values.


[#81607] Monday, December 3, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
myakylas

Total Points: 66
Total Questions: 85
Total Answers: 95

Location: Guadeloupe
Member since Sat, Aug 22, 2020
4 Years ago
myakylas questions
Thu, Apr 28, 22, 00:00, 2 Years ago
Thu, Apr 8, 21, 00:00, 3 Years ago
Sat, Sep 19, 20, 00:00, 4 Years ago
;