Byte Calculator Using Javascript
Submitted by jaredgwapo on Monday, February 8, 2016 - 16:29.
Language
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.
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]
Directions
First we will write our html 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>
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.
Add new comment
- 209 views