OZONE Asylum
Forums
DHTML/Javascript
Decimal to Binary Conversion
This page's ID:
28070
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Sorry poi, I wrote this code at 3.30am when my eyes were not seeing so straight. Thanks for the help, I have made a few adjustments. Does javascript have a built in function for binary -> hex? i.e. dstBase = 6 ( I think ). I tried adding a part to do that but to no avail. [code]<html> <head> <title>TME 3 Part 2</title> <script language="Javascript" type="text/javascript"> function ConvertBinary() { if (document.form1.dropdown.value == "dectobin") { var inBase = 10, outBase = 2 } if (document.form1.dropdown.value == "bintohex") { var inBase = 2, outBase = 6 } else { var inBase = 2, outBase = 10 } var originalValue = document.form1.original1.value var originalNumber = parseInt( originalValue, inBase ); if( isNaN(originalNumber) ) var resultString = 'invalid input' else var resultString = originalNumber.toString( outBase ) document.form1.result1.value= resultString; } </script> </head> <body> <center> <form name="form1" onsubmit="return false;"> Input:<input type="text" name="original1" value=""> Output:<input type="text" name="result1"><p> <select name="dropdown"> <option value="dectobin">Decimal to Binary <option value="bintodec">Binary to Decimal <option value="bintohex">Binary to Hex </select><br> <input type="button" onClick="ConvertBinary(this.form);" value="Convert Number!"> </center> </form> </body> </html>[/code]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »