i da oktalni broj prikazem na drugo tekst polje forme?
Pokusao sam sa parseInt(dec,8),kao i sa parseInt(0dec) ali nisam uspeo,a na
http://www.w3schools.com/jsref/jsref_parseInt.asp
sam nasao da pise:
If the string begins with "0", the radix is 8 (octal). This feature is
deprecated
This feature is deprecated=ova osobina nije odobrena
Na sajtu:
http://jsfromhell.com/number/base-conversor/download
sam nasao deo koda koji pomocu metode (dec).toBase(8) vraca oktalni broj od dekadnog broja dec.
Sa tom metodom sam uspeo da ispisem konverziju na txt polje txtOct tako sto sam direktno stavio broj recimo 20:
(20).toBase(8), a meni treba za bilo koji broj koji se otkuca u txt polje txtDec da izvrsim konverziju.
Code:
<html>
<head>
<title> KONVERTOVANJE DEC U OCT </title>
<script language="JavaScript">
Number.prototype.toBase = function(b, c){
var s = "", n = this;
if(b > (c = (c || "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz").split("")).length || b < 2) return "";
while(n)
s = c[n % b] + s, n = Math.floor(n / b);
return s;
};
function izracunaj(){
var dec=document.forma.txtDec.value;
var oct=((dec).toBase(8));
document.forma.txtOct.value=oct;
}
</script>
</head>
<body>
<form name="forma" >
dekadni broj:<input type="text" name="txtDec" /> <br />
<input type="button" onClick="izracunaj()" value="KONVERTUJ DEC U OCT BROJ" /> <br/>
oktalni broj:<input type="text" name="txtOct">
</form>
</body>
</html>
<html>
<head>
<title> KONVERTOVANJE DEC U OCT </title>
<script language="JavaScript">
Number.prototype.toBase = function(b, c){
var s = "", n = this;
if(b > (c = (c || "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz").split("")).length || b < 2) return "";
while(n)
s = c[n % b] + s, n = Math.floor(n / b);
return s;
};
function izracunaj(){
var dec=document.forma.txtDec.value;
var oct=((dec).toBase(8));
document.forma.txtOct.value=oct;
}
</script>
</head>
<body>
<form name="forma" >
dekadni broj:<input type="text" name="txtDec" /> <br />
<input type="button" onClick="izracunaj()" value="KONVERTUJ DEC U OCT BROJ" /> <br/>
oktalni broj:<input type="text" name="txtOct">
</form>
</body>
</html>