Javascript - Simple Currency Converter

Submitted by: 
Visitors have accessed this post 8188 times.

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.

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

And this is the link for the bootstrap that has been used for the layout of the calculator

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

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
  5. <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
  6. <script src="converter.js"></script>
  7. </head>
  8. <nav class="navbar navbar-default">
  9. <div class="container-fluid">
  10. <a class="navbar-brand" href="<a href="">Sourcecodester</a>
  11. " rel="nofollow">">Sourcecodester</a>
  12. </a> </div>
  13. </nav>
  14. <div class="col-md-3"></div>
  15. <div class="col-md-6 well">
  16. <h3 class="text-primary">Javascript - Simple Currency Converter</h3>
  17. <hr style="border-top:1px dotted #ccc;">
  18. <div class="col-md-2"></div>
  19. <div class="col-md-8">
  20. <h4>Converter</h4>
  21. <hr style="border-top:1px groovy #ccc;"/>
  22. <div class="form-group">
  23. <select onchange="Currency(); Calculate()" class="form-control" id="converter" style="width:30%;">
  24. <option value="Dollar">Dollar</option>
  25. <option value="Pound">Pound</option>
  26. <option value="Euro">Euro</option>
  27. <option value="Yen">Yen</option>
  28. <option value="Yuan">Yuan</option>
  29. </select>
  30. <br />
  31. <input type="number" oninput="Calculate()" class="form-control" id="value1"/>
  32. </div>
  33. <br /><br />
  34. <div class="form-group">
  35. <label>Philippine Peso</label>
  36. <input type="number" class="form-control" id="value2" disabled="disabled"/>
  37. </div>
  38. </div>
  39. </div>
  40. </body>
  41. </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

  1. function Currency(){
  2. y = document.getElementById("converter").value;
  3. return y;
  4. }
  6. function Calculate(){
  7. y = Currency();
  9. x = document.getElementById("value1").value;
  11. if(x == ""){
  12. document.getElementById("value2").value = "";
  13. }else{
  14. switch(y){
  15. case "Dollar":
  16. document.getElementById("value2").value = x * 51.89;
  17. break;
  19. case "Pound":
  20. document.getElementById("value2").value = x * 72.39;
  21. break;
  23. case "Euro":
  24. document.getElementById("value2").value = x * 63.84;
  25. break;
  27. case "Yen":
  28. document.getElementById("value2").value = x * 0.49;
  29. break;
  31. case "Yuan":
  32. document.getElementById("value2").value = x * 8.20;
  33. break;
  34. }
  35. }
  36. }

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!!

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.