Thursday, May 24, 2018

javascript - Round converted value from html form to nearest hundredth using jQuery

I have an html form that contains an input field for a person's weight. The input field type is a textbox and allows a user to enter their weight. There is a dropdown next to it that allows for the user to convert their weight from pounds to kilograms. When the user changes the weight unit, the value in the textbox is converted.



So when a user enters their weight in pounds and then selects kilograms from the dropdown, I want this value to be rounded to the nearest hundredth.



HTML:




         




JavaScript:




var kg = 0.45359237

$(document).ready(function() {
$("#weight_unit").change(function() {
if ($(this).val() == "kg") {
($("#weight_value").val( $("#weight_value").val()*kg))
} else {
$("#weight_value").val( $("#weight_value").val()/kg)
}
});

});


Any help would be greatly appreciated!

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...