<script type="text/javascript">function bandwidth(bytees,type) { var value = bytees; var res; if(!isNaN(value)) { if(type == "KB") { value = Math.round((bytees/1024)*1000000)/1000000; res = value+" KB"; } if(type == "MB") { value = Math.round((bytees/[Math.pow(1024,2)])*1000000)/1000000; res = value+" MB"; } if(type == "GB") { value = Math.round((bytees/[Math.pow(1024,3)])*1000000)/1000000; res = value+" GB"; } return res; } else { return "Error"; } } function tests(aaa,ty) { var ss = bandwidth(aaa,ty); alert(ss); return false; } </script> <form name="test" 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> </select> <input type=submit value=result> </form>