JavaScript - Simple Foot To Yard Conversion
Submitted by razormist on Monday, February 4, 2019 - 22:55.
In this tutorial we will create a Simple Foot To Yard Conversion using JavaScript. JavaScript is a scripting or programming language that allows you to implement complex things on web pages. It is widely used in designing a stunning website. It is an interpreted programming language that has a capabilities of Object-Oriented. So Let's do the coding...
Getting started:
This is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.The Main Interface
This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as index.html.- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- </head>
- <body>
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- </div>
- </nav>
- <div class="col-md-6">
- <hr style="border-top:1px dotted #ccc;" />
- <div class="col-md-6">
- <div style="border:1px solid #000; padding:20px; border-radius:10px;">
- <div class="form-group">
- <input type="number" id="foot1" placeholder="Enter number here" class="form-control"/>
- </div>
- <div class="form-group">
- <input type="text" id="yard1" class="form-control" readonly="readonly"/>
- </div>
- </div>
- </div>
- <div class="col-md-6">
- <div style="border:1px solid #000; padding:20px; border-radius:10px;">
- <div class="form-group">
- <input type="number" id="yard2" placeholder="Enter number here" class="form-control"/>
- </div>
- <div class="form-group">
- <input type="text" id="foot2" class="form-control" readonly="readonly"/>
- </div>
- </div>
- </div>
- </div>
- </body>
- </html>
Creating the Script
This code contains the script of the application. This code will automatically convert the foot to yard value or vice versa. To do this just copy and write these block of codes as shown below inside the text editor and save it as script.js inside the js folder.- function convertToYard(){
- var foot1 = document.getElementById("foot1").value;
- if(foot1 != ""){
- var number = parseFloat(foot1);
- document.getElementById("yard1").value = (number*0.333333)+"yd";
- }else{
- alert("Please enter something");
- }
- }
- function convertToFoot(){
- var yard2 = document.getElementById("yard2").value;
- if(yard2 != ""){
- var number = parseFloat(yard2);
- document.getElementById("foot2").value = (number*3)+"ft";
- }else{
- alert("Please enter something");
- }
- }
- </javascrip>
- There you have it we successfully created a <strong>Simple Foot To Yard Conversion</strong> using JavaScript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Add new comment
- 35 views