KennethTejadaKGJL
Meta Breaker
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
400 XP
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 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
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
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!!
Download
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"
/
>
- <script
src
=
"converter.js"
></
script
>
- </
head
>
- <body
>
- <nav class
=
"navbar navbar-default"
>
- <div
class
=
"container-fluid"
>
- <a
class
=
"navbar-brand"
href
=
"https://sourcecodester.com"
>
Sourcecodester</
a
>
- </
div
>
- </
nav>
- <div
class
=
"col-md-3"
></
div
>
- <div
class
=
"col-md-6 well"
>
- <h3
class
=
"text-primary"
>
Javascript - Simple Currency Converter</
h3
>
- <hr
style
=
"border-top:1px dotted #ccc;"
>
- <div
class
=
"col-md-2"
></
div
>
- <div
class
=
"col-md-8"
>
- <h4
>
Converter</
h4
>
- <hr
style
=
"border-top:1px groovy #ccc;"
/
>
- <div
class
=
"form-group"
>
- <select
onchange
=
"Currency(); Calculate()"
class
=
"form-control"
id
=
"converter"
style
=
"width:30%;"
>
- <option
value
=
"Dollar"
>
Dollar</
option
>
- <option
value
=
"Pound"
>
Pound</
option
>
- <option
value
=
"Euro"
>
Euro</
option
>
- <option
value
=
"Yen"
>
Yen</
option
>
- <option
value
=
"Yuan"
>
Yuan</
option
>
- </
select
>
- <br
/
>
- <input
type
=
"number"
oninput=
"Calculate()"
class
=
"form-control"
id
=
"value1"
/
>
- </
div
>
- <br
/
><br
/
>
- <div
class
=
"form-group"
>
- <label
>
Philippine Peso</
label
>
- <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
;
- }
- }
- }
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!!
Download
You must upgrade your account or reply in the thread to view hidden text.