Javascript - Simple Currency Converter
Submitted by razormist on Saturday, March 17, 2018 - 23:32.
In this tutorial we will create a Simple Currency Converter using Javascript. JavaScript is a scripting or programming language that allows you to implement complex things on web pages. It can renders web pages in an interactive and dynamic fashion. It is widely used in designing a stunning website. This code can be used as your converter to your mathematical problem. So Let's do the coding.
There you have it we successfully created a Simple Currency Converter
using javascript. I hope that this very simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!
Before we started:
First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html. And this is the link for the bootstrap that has been used for the layout of the calculator https://getbootstrap.com/The Main Interface
This code contains the interface of the application. This code will render application and display the form that will be use in converting. 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>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
- </head>
- <body>
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- </div>
- </nav>
- <div class="col-md-6 well">
- <hr style="border-top:1px dotted #ccc;">
- <div class="col-md-8">
- <hr style="border-top:1px groovy #ccc;"/>
- <div class="form-group">
- <select onchange="Currency(); Calculate()" class="form-control" id="converter" style="width:30%;">
- </select>
- <br />
- <input type="number" oninput="Calculate()" class="form-control" id="value1"/>
- </div>
- <div class="form-group">
- <input type="number" class="form-control" id="value2" disabled="disabled"/>
- </div>
- </div>
- </div>
- </body>
- </html>
Creating the Script
This code contains the script of the application. This code will convert input value every time you enter some number. To do this just copy write the code as shown below inside the text editor and save it as converter.js- function Currency(){
- y = document.getElementById("converter").value;
- return y;
- }
- function Calculate(){
- y = Currency();
- x = document.getElementById("value1").value;
- if(x == ""){
- document.getElementById("value2").value = "";
- }else{
- switch(y){
- case "Dollar":
- document.getElementById("value2").value = x * 51.89;
- break;
- case "Pound":
- document.getElementById("value2").value = x * 72.39;
- break;
- case "Euro":
- document.getElementById("value2").value = x * 63.84;
- break;
- case "Yen":
- document.getElementById("value2").value = x * 0.49;
- break;
- case "Yuan":
- document.getElementById("value2").value = x * 8.20;
- break;
- }
- }
- }
Comments
Add new comment
- Add new comment
- 10801 views