THE BIG ONE
Anime Historian
Divine
LEVEL 1
500 XP
In this tutorial we will create a Dynamically Get Area Of Parallelogram using JavaScript. This code will dynamically calculate the area of the parallelogram when the user entered the inputs in the form. This code use onclick function to call a specific function that compute the area of parallelogram by the use of a certain formula. This program is a user-friendly feel free to use it in your system.
We will use JavaScript to allow you to implement complex things on web pages. It enables you to create dynamically updating content and add some interactive visual for the user transactions.
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.
Creating the Script
This code contains the script of the application. This code will compute the area of the parallelogram 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
There you have it we successfully created a Dynamically Get Area Of Parallelogram 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!
Download
We will use JavaScript to allow you to implement complex things on web pages. It enables you to create dynamically updating content and add some interactive visual for the user transactions.
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"
>
- <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 - Dynamically Get Area Of Parallelogram</
h3
>
- <hr
style
=
"border-top:1px dotted #ccc;"
/
>
- <div
class
=
"col-md-4"
>
- <div
class
=
"form-group"
>
- <label
>
b</
label
>
- <input
type
=
"number"
class
=
"form-control"
id
=
"b"
/
>
- </
div
><div
class
=
"form-group"
>
- <label
>
h</
label
>
- <input
type
=
"number"
class
=
"form-control"
id
=
"h"
/
>
- </
div
>
- <center
><button
type
=
"button"
class
=
"btn btn-primary"
id
=
"btn"
onclick
=
"calculateArea(this);"
>
Calculate</
button
>
<button
type
=
"button"
class
=
"btn btn-success"
onclick
=
"reset();"
>
Reset</
button
></
center
>
- </
div
>
- <div
class
=
"col-md-8"
>
- <br
/
>
- <div
id
=
"result"
></
div
>
- </
div
>
- </
div
>
- <script
src
=
"js/script.js"
></
script
>
- </
body
>
- </
html
>
Creating the Script
This code contains the script of the application. This code will compute the area of the parallelogram 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
- function
reset(
)
{
- document.getElementById
(
'b'
)
.value
=
""
;
- document.getElementById
(
'h'
)
.value
=
""
;
- document.getElementById
(
'result'
)
.innerHTML
=
""
;
- document.getElementById
(
'btn'
)
.removeAttribute
(
'disabled'
)
;
- }
- function
calculateArea(
btn)
{
- var
b =
document.getElementById
(
'b'
)
.value
;
- var
h =
document.getElementById
(
'h'
)
.value
;
- if
(
b !=
""
&&
h !=
""
)
{
- var
par_b=
parseInt(
b)
;
- var
par_h=
parseInt(
h)
;
- var
area=
par_b*
par_h;
- btn.setAttribute
(
'disabled'
,
'disabled'
)
;
- document.getElementById
(
'result'
)
.innerHTML
=
"<center><label style='font-size:26px;'>The Area of Parallelogram is</label> <br /><span class='text-primary' style='font-size:30px;'>"
+
area+
"</span></center>"
;
- }
else
{
- alert(
"Please enter something first!"
)
;
- }
- }
There you have it we successfully created a Dynamically Get Area Of Parallelogram 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!
Download
You must upgrade your account or reply in the thread to view hidden text.