JRS: In article <bdhkss$cfp$1 (AT) slb6 (DOT) atl.mindspring.net>, seen in
news:comp.lang.javascript, TSK <susannek (AT) mindspring (DOT) com> posted at Fri,
27 Jun 2003 10:36:54 :-
Quote:
My code is included below. Your help
will be greatly appreciated. |
Code for News should be written with 72-character margin, or otherwise
arranged so that the sending newsreader does not wrap it. Why should we
have to tediously reassemble the pieces when you could so easily have
done it yourself?
The whole method is far too long.
<URL:http://www.merlyn.demon.co.uk/js-maths.htm#Base> does a similar
task in three lines of script :
function BCvt() { with (document.forms['Frm1']) {
out.value = parseInt(inp.value, inpbase.value).
toString(outbase.value).toUpperCase() } }
That converts from any base in 2..36 to any base in 2..36.
You test your input number. Easier to test it with a RegExp :
OK = /^\d+$/.test(inp.value) // is it just 1 or more digits?
after which +inp.value gets the value, as a Number, with no possible
error (except too big, which you did not test).
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MSIE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.