typz0
Digital Marketplace Creator
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.
This will be our javacsript code.
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.
Directions
First we will write our html code.
- <form
name
=
"bandwidth"
method
=
"post"
>
- <p
><input
type
=
"text"
name
=
"original"
size
=
"20"
value
=
1024
>
<select
size
=
"1"
name
=
"units"
>
- <option
value
=
"Bytes"
>
Bytes</
option
>
- <option
value
=
"Kb"
>
Kb</
option
>
- <option
value
=
"Mb"
>
Mb</
option
>
- <option
value
=
"Gb"
>
Gb</
option
>
- </
select
>
<input
type
=
"button"
value
=
"Calculate"
name
=
"B1"
onClick
=
"calculate()"
></
p
>
- </
form
>
This will be our javacsript code.
- <
script>
- var
bytevalue=
0
- function
calculate(
)
{
- var
invalue=
document.bandwidth
.original
.value
- var
selectunit=
document.bandwidth
.units
.options
[
document.bandwidth
.units
.selectedIndex
]
.value
- if
(
selectunit==
"Bytes"
)
- bytevalue=
invalue
- else
if
(
selectunit==
"Kb"
)
- bytevalue=
invalue*
1024
- else
if
(
selectunit==
"Mb"
)
- bytevalue=
invalue*
1024
*
1024
- else
if
(
selectunit==
"Gb"
)
- bytevalue=
invalue*
1024
*
1024
*
1024
- 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
"
)
- }
- </
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.