Bandwidth converting javascript function

This script function will help you to convert bandwidth to bytes from Kilobyte or Megabyte or Gigabyte


  • The javascript function will return bandwidth in bytes from KB/MB/GB.
  • You have to pass two arguments bytes and type to convert from (KB or MB or GB).
  • It returns 0 on passing wrong arguments.
  • Just copy the code in to your page and use it.


Bandwith conversion from KB, MB or GB to byte value :
Enter the value and test it
[ e.g: 2 or 20 ]


Javascript Code
<!-- Script by -->
<script type="text/javascript">
function bandwidth(bytees,type)
var value = bytees;
var res;
if(type == "KB")
value = value*1024; else if(type == "MB")
value = value*[Math.pow(1024,2)]; else if(type == "GB")
value = value*[Math.pow(1024,3)]; else
return "error";
res = value+" bytes"; return res; } else { return "Error"; } } function tests(aaa,ty) { var ss = bandwidth(aaa,ty); alert(ss); return false; } </script>
<!-- Script by -->
  • Release Date - 02-03-2005
  • Get free version without ©copyright link for just $10/-
  • For customization of this script or any script development, mail to


  • He we have explained with a form
  • Creating the form using following HTML code
  •   <form name="test" color=blue>onSubmit="return tests(test.mailf.value,test.sel.value)">
    <input name=mailf type=text>
    <select name=sel>
    <option value="KB">KB</option>
    <option value="MB">MB</option>
    <option value="GB">GB</option>
    <input type=submit value=calculate>
  • The javascript function tests() is triggered on submission of the form.
  • Just copy the javascript code and use it for free.


Related Scripts

Free Javascript Scripts

Ask Questions

Ask Question