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

Byte Calculator Using Javascript

typz0

Digital Marketplace Creator
T Rep
0
0
0
Rep
0
T Vouches
0
0
0
Vouches
0
Posts
201
Likes
180
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 400 XP
In this tutorial, I am going to teach you how to make a byte calculator using javascript. Just download the source code below and follow the instructions.

Directions

First we will write our html code.
  1. <form

    name

    =

    "bandwidth"

    method

    =

    "post"

    >
  2. <p

    ><input

    type

    =

    "text"

    name

    =

    "original"

    size

    =

    "20"

    value

    =

    1024

    >

    <select

    size

    =

    "1"

    name

    =

    "units"

    >
  3. <option

    value

    =

    "Bytes"

    >

    Bytes</

    option

    >
  4. <option

    value

    =

    "Kb"

    >

    Kb</

    option

    >
  5. <option

    value

    =

    "Mb"

    >

    Mb</

    option

    >
  6. <option

    value

    =

    "Gb"

    >

    Gb</

    option

    >
  7. </

    select

    >

    <input

    type

    =

    "button"

    value

    =

    "Calculate"

    name

    =

    "B1"

    onClick

    =

    "calculate()"

    ></

    p

    >
  8. </

    form

    >

This will be our javacsript code.
  1. <

    script>

  2. var

    bytevalue=

    0
  3. function

    calculate(

    )

    {
  4. var

    invalue=

    document.bandwidth

    .original

    .value
  5. var

    selectunit=

    document.bandwidth

    .units

    .options

    [

    document.bandwidth

    .units

    .selectedIndex

    ]

    .value
  6. if

    (

    selectunit==

    "Bytes"

    )
  7. bytevalue=

    invalue
  8. else

    if

    (

    selectunit==

    "Kb"

    )
  9. bytevalue=

    invalue*

    1024
  10. else

    if

    (

    selectunit==

    "Mb"

    )
  11. bytevalue=

    invalue*

    1024

    *

    1024
  12. else

    if

    (

    selectunit==

    "Gb"

    )
  13. bytevalue=

    invalue*

    1024

    *

    1024

    *

    1024

  14. alert (

    invalue+

    " "

    +

    selectunit+

    " is equal to:\n

    \n

    - "

    +

    bytevalue+

    " Bytes\n

    - "

    +

    Math

    .round

    (

    bytevalue/

    1024

    )

    +

    " Kb\n

    - "

    +

    Math

    .round

    (

    bytevalue/

    1024

    /

    1024

    )

    +

    " Mb\n

    - "

    +

    Math

    .round

    (

    bytevalue/

    1024

    /

    1024

    /

    1024

    )

    +

    " Gb\n

    "

    )
  15. }

  16. </

    script>

You have successfully created a simple byte calculator that you can use in your system. For more information, suggestions and questions just comment below or email me at [email protected]

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.

2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

 

442,401

317,942

317,951

Top