
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to create a weight converter with HTML and JavaScript?
To create a weight converter with HTML and JavaScript, the code is as follows −
Example
<!DOCTYPE html> <html> <head> <style> body{ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } input,span{ font-size: 20px; } </style> </head> <body> <h1>Weight Converter</h1> <h2>Type weight in kg to convert it into grams</h2> <p> <label>Kilogram</label> <input id="inputKG" type="number" placeholder="Kilogram" oninput="KgtoGConverter(this.value)" onchange="KgtoGConverter(this.value)"> </p> <p>Grams: <span id="outputGrams"></span></p> <script> function KgtoGConverter(weight) { document.getElementById("outputGrams").innerHTML=weight*1000; } </script> </body> </html>
Output
The above code will produce the following output −
On typing some weight in KGs −
- Related Articles
- How to create a temperature converter with HTML and JavaScript?
- How to create a length converter with HTML and JavaScript?
- How to create a speed converter with HTML and JavaScript?
- How to Create a Currency Converter in JavaScript?
- How to create infix to postfix converter in JavaScript?
- How to create a draggable HTML element with JavaScript and CSS?
- How to create a Bibliography with HTML?
- How to create a revealing sidebar using HTML, CSS, and JavaScript?
- How to Create a Color Picker using HTML, CSS, and JavaScript?
- How to Create a Parallax Effect using HTML, CSS, and JavaScript?
- How to Create a Binary Calculator using HTML, CSS and JavaScript?
- How to create a signup form with HTML and CSS?
- Temperature converter using JavaScript
- How to create a download link with HTML?
- How to Create a Profit and Loss Calculator using HTML, CSS, and JavaScript?

Advertisements