JavaScript - Simple Money Currency Converter

Submitted by: 
Visitors have accessed this post 195 times.

In this tutorial we will create a Simple Money Currency Converter using JavaScript. The code can convert any currency when the user input some amount and click the convert button. The code use onclick() to initiate a switch function in order to convert the given amount base on the selected currency. This is a user-friendly program feel free to modify it.

We will use JavaScript to add some new feature to the website interface by actually written into an HTML page. It is what gives your page a different interactive elements and animation that engage a user.

Getting Started:

This is the link for the bootstrap that i used for the layout design

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.

  1. <!DOCTYPE html>
  2. <!DOCTYPE html>
  3. <html lang="en">
  4. <head>
  5. <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
  6. <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
  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 Money Currency Converter</h3>
  17. <hr style="border-top:1px dotted #ccc;">
  18. <div class="col-md-3"></div>
  19. <div class="col-md-6">
  20. <div class="form-group">
  21. <label>Enter an amount</label>
  22. <select class="form-control" id="currency" style="width:30%;">
  23. <option value="Dollar">Dollar</option>
  24. <option value="Pound">Pound</option>
  25. <option value="Euro">Euro</option>
  26. <option value="Yen">Yen</option>
  27. <option value="Yuan">Yuan</option>
  28. </select>
  29. <br />
  30. <input type="number" class="form-control" id="amount"/>
  31. </div>
  32. <center><button class="btn btn-primary" onclick="convert();">Convert</button></center>
  33. <br />
  34. <div class="form-group">
  35. <label>Philippine Peso</label>
  36. <input type="number" class="form-control" id="result" readonly="readonly"/>
  37. </div>
  38. </div>
  39. </div>
  40. </body>
  41. <script src="js/script.js"></script>
  42. </html>

Creating the Script

This code contains the script of the application. This code will convert the currency when the button is clicked. 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 directory

  1. function convert(){
  2. var amount=document.getElementById("amount").value;
  3. var currency=document.getElementById("currency").value;
  4. if(amount == ""){
  5. alert('Please enter something first');
  6. }else{
  7. switch(currency){
  8. case "Dollar":
  9. document.getElementById("result").value = amount * 51.89;
  10. break;
  12. case "Pound":
  13. document.getElementById("result").value = amount * 72.39;
  14. break;
  16. case "Euro":
  17. document.getElementById("result").value = amount * 63.84;
  18. break;
  20. case "Yen":
  21. document.getElementById("result").value = amount * 0.49;
  22. break;
  24. case "Yuan":
  25. document.getElementById("result").value = x * 8.20;
  26. break;
  27. }
  28. }
  29. }

There you have it we successfully created a Simple Money Currency Converter 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

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.