What we generally call “weight” in our daily lives is theoretically referred to as mass, and it calculates the amount of matter in an object. But we can use mass and weight almost interchangeably by simply multiplying or dividing it by the Earth’s gravitational acceleration, g and this is because of gravitational force the Earth exerts on us is approximately constant. To prevent misunderstanding or unnecessary confusion, we’re talking about mass units, but we’re referring to them as weight units.
Create a Weight Converter
Step 1: Add HTML
First you have to create an input field to convert a value from one weight measurement to another.
The <input> tag use as an input field where the users can enter their data and placeholder is attribute that specifies a short hint that describes the expected value of an <input> element to be enter by user.
The oninput is a event occurs when an element gets user input i.e. when the value of an <input> or <textarea> element is changed. In above code this attribute contains value “kiloweightConvert(this.value)” and it works when oninput event triggered.
The onchange event is occur when the value of an element has been changed.
These both events are similar but the difference is that the oninput event gets activated after the value of an element has changed, while onchange event occurs when the element loses its focus, after the content has been changed. The onchange event is also works on <select> elements.
Second, create an output field for result of the conversion.
<span> tag is a generic inline container for inline elements and content which is used to mark up a part of a text, for grouping and applying styles to inline elements.
You can also try the following measurements to make a weight converter.
To get your head around the conversions between different units, feel free to use the weight conversion chart given below. This conversion table will be very useful in designing the weight converter according to your preferences.
Pounds to other Measurements Ounces to other Measurements Pounds to Kilograms kilograms=lb/2.2046 Ounces to Pounds pounds=oz*0.0625 Pounds to Ounces ounces=lb*16 Ounces to Kilograms kilograms=oz/35.274 Pounds to Grams grams=lb/0.0022046 Ounces to Grams grams=oz/0.035274 Pounds to Stones stones=lb*0.071429 Ounces to Stones stones=oz*0.0044643 Grams to other Measurements Stones to other Measurements Grams to Pounds pounds=g*0.0022046 Stones to Pounds ponds=st*14 Grams to Kilograms kilograms=g/1000 Stones to Kilograms kilograms=st/0.15747 Grams to Ounces ounces=g*0.035274 Stones to Ounces ounces=st*224 Grams to Stones stones=g*0.00015747 Stones to Grams grams=st/0.00015747
Example: Given below shows how to convert a value from Kilogram to other measurements: