• We just launched and are currently in beta. Join us as we build and grow the community.

JavaScript - Dynamically Get Area Of Parallelogram

THE BIG ONE

Anime Historian
Divine
T Rep
0
0
0
Rep
0
T Vouches
0
0
0
Vouches
0
Posts
76
Likes
33
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
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.
  1. <!DOCTYPE html>
  2. <html

    lang

    =

    "en"

    >
  3. <head

    >
  4. <meta

    charset

    =

    "UTF-8"

    name

    =

    "viewport"

    content

    =

    "width=device-width, initial-scale=1"

    /

    >
  5. <link

    rel

    =

    "stylesheet"

    type

    =

    "text/css"

    href

    =

    "css/bootstrap.css"

    /

    >
  6. </

    head

    >
  7. <body

    >
  8. <nav class

    =

    "navbar navbar-default"

    >
  9. <div

    class

    =

    "container-fluid"

    >
  10. <a

    class

    =

    "navbar-brand"

    href

    =

    "https://sourcecodester.com"

    >

    Sourcecodester</

    a

    >
  11. </

    div

    >
  12. </

    nav>
  13. <div

    class

    =

    "col-md-3"

    ></

    div

    >
  14. <div

    class

    =

    "col-md-6 well"

    >
  15. <h3

    class

    =

    "text-primary"

    >

    JavaScript - Dynamically Get Area Of Parallelogram</

    h3

    >
  16. <hr

    style

    =

    "border-top:1px dotted #ccc;"

    /

    >
  17. <div

    class

    =

    "col-md-4"

    >
  18. <div

    class

    =

    "form-group"

    >
  19. <label

    >

    b</

    label

    >
  20. <input

    type

    =

    "number"

    class

    =

    "form-control"

    id

    =

    "b"

    /

    >
  21. </

    div

    ><div

    class

    =

    "form-group"

    >
  22. <label

    >

    h</

    label

    >
  23. <input

    type

    =

    "number"

    class

    =

    "form-control"

    id

    =

    "h"

    /

    >
  24. </

    div

    >
  25. <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

    >
  26. </

    div

    >
  27. <div

    class

    =

    "col-md-8"

    >
  28. <br

    /

    >
  29. <div

    id

    =

    "result"

    ></

    div

    >
  30. </

    div

    >
  31. </

    div

    >

  32. <script

    src

    =

    "js/script.js"

    ></

    script

    >
  33. </

    body

    >
  34. </

    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
  1. function

    reset(

    )

    {
  2. document.getElementById

    (

    'b'

    )

    .value

    =

    ""

    ;
  3. document.getElementById

    (

    'h'

    )

    .value

    =

    ""

    ;
  4. document.getElementById

    (

    'result'

    )

    .innerHTML

    =

    ""

    ;
  5. document.getElementById

    (

    'btn'

    )

    .removeAttribute

    (

    'disabled'

    )

    ;
  6. }


  7. function

    calculateArea(

    btn)

    {
  8. var

    b =

    document.getElementById

    (

    'b'

    )

    .value

    ;
  9. var

    h =

    document.getElementById

    (

    'h'

    )

    .value

    ;

  10. if

    (

    b !=

    ""

    &&

    h !=

    ""

    )

    {
  11. var

    par_b=

    parseInt(

    b)

    ;
  12. var

    par_h=

    parseInt(

    h)

    ;

  13. var

    area=

    par_b*

    par_h;

  14. btn.setAttribute

    (

    'disabled'

    ,

    'disabled'

    )

    ;

  15. 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>"

    ;

  16. }

    else

    {
  17. alert(

    "Please enter something first!"

    )

    ;
  18. }

  19. }

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.
 

452,292

323,340

323,349

Top