Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/04/2011, 07:21
Polkiko
 
Fecha de Ingreso: enero-2011
Mensajes: 59
Antigüedad: 13 años, 3 meses
Puntos: 2
Box calculador

Hola,

Soy nuevo en esto de las paginas web.
Me gustaria hacer "un conversor"
La idea es que al poner un numero en un box, en otro box me salga lo que correponda

No me explico bien...

Seria algo parecido a este codigo:
<title>Puntos de Experiencia, nivel</title>
<meta value="[email protected]" name="author"> <SCRIPT LANGUAGE="JavaScript">
<!-- Hide scripts from old browsers

function reload()
{
location.reload();
}
function Decimal_to_binary(x)
{
answer=new Object();
x2=x;
log2=0;
while(x2>=2){
x2=x2/2;
log2=log2+1;
}

for(l2=log2; l2>=0; l2--){
power=Math.pow(2,l2);
if (x>=power) {
answer[l2]="1";
x=x-power;
}
else answer[l2]="0";
}
for (i=log2; i>=0; i--){
document.forms[0].elements[1].value+=(answer[i]);

}
}
function Binary_to_decimal(x)
{

y=parseInt(x,2);
if (isNaN(y))
alert(x + " no es un nº binario!");
else
document.forms[1].elements[1].value=y;
}

function explaindec(x)
{

var ex = open("","explanation","width=300,height=150,scroll bars=yes");

ex.document.write("El nº <FONT COLOR=BLUE>" + x +"</FONT>");
answer=new Object();
x2=x;
log2=0;
while(x2>=2){
x2=x2/2;
log2=log2+1;
}
ex.document.write(" Se puede expresar: <BR><FONT COLOR=BLUE>");
for(l2=log2; l2>=0; l2--){
power=Math.pow(2,l2);
if (x>=power) {
answer[l2]="1";
x=x-power;
if (l2<log2)
ex.document.write(" " + "+" + " ");
ex.document.write(power);
}
else answer[l2]="0";
}
ex.document.write("</FONT><BR>La solución es: ");
ex.document.write("<FONT COLOR=RED>");
for (i=log2; i>=0; i--){
ex.document.write(answer[i]);
}

ex.document.write("</FONT> ");
ex.document.write("<P>");
ex.document.write("<FORM>");
ex.document.write("<INPUT TYPE=BUTTON VALUE='Continuar' onClick='window.close()'>");
ex.document.write("</FORM>");
}

function explainbin(x)
{


y=parseInt(x,2);
if (isNaN(y)){
alert(x + " no es un nº binario");
return;
}

var ex = open("","explanation","width=300,height=150,scroll bars=yes");
ex.document.write("El nº <FONT COLOR=BLUE>" + x +"</FONT>");
ex.document.write(" representa: <BR><FONT COLOR=BLUE>");
hipow=x.length-1;
for(l=0;l<x.length;l++){
digit=x.substring(l,l+1);
if (digit=='1'){
power=Math.pow(2,hipow-l);
if (l>0)
ex.document.write(" " + "+" + " ");
ex.document.write(power);
}
}
ex.document.write("</FONT><BR>la solución es: ");
ex.document.write("<FONT COLOR=RED>");
ex.document.write(y);
ex.document.write("</FONT> ");
ex.document.write("<P>");
ex.document.write("<FORM>");
ex.document.write("<INPUT TYPE=BUTTON VALUE='Continuar' onClick='window.close()'>");
ex.document.write("</FORM>");
}

function answer(correct,which) {
if (document.forms[0].elements[which].value == correct) {
alert("Correcto!");
}
else {
alert("Prueba otra vez.");
}
}
function give(correct,which) {

document.forms[0].elements[which].value = correct;
}
//End hide -->
</SCRIPT>
<h3>Javascript, calculadora binario/decimal</h3>
<hr />
<font size="2"> </font>
<p><font size="2"> </font></p>
<form name="dectobin">
N&ordm; Decimal a convertir: <input maxlength="7" size="7" name="dec" /> <br />
Representaci&oacute;n Binaria: <input type="bin" readonly="readonly" input="" maxlength="25" size="25" name="bin" /> <br />
<input type="button" onclick="Decimal_to_binary(document.forms[0].elements[0].value)" value="Convertir" /> <input type="button" onclick="explaindec(document.forms[0].elements[0].value)" value="&iquest;Porque?" /> <br />
<br />
<input type="Reset" onclick="reload()" value="Otra Vez!" />
</form>
<form name="bintodec">
N&ordm; Binario a convertir: <input maxlength="24" size="24" name="dec" /> <br />
Represenaci&oacute;n Decimal: <input type="bin" readonly="readonly" input="" maxlength="7" size="7" name="bin" /> <br />
<input type="button" onclick="Binary_to_decimal(document.forms[1].elements[0].value)" value="Convertir" /> <input type="button" onclick="explainbin(document.forms[1].elements[0].value)" value="&iquest;Porqu&eacute;?" /> <br />
<br />
<input type="Reset" value="Otra Vez!" />
</form>
</meta>

Aqui lo pueden ver:
http://clandeaprendices.es.tl/Pagina-de-pruebas.htm


Al darle a convertir pasa ese numero a numero binario

Pues yo quiero que al darle a convertir, dependiendo del numero de arriba abajo ponga otro...(que mal me explico)

Por ejemplo

Del numero 1 al 20
y en el segundo que ponga
Nivel: 1

Del numero 21 al 40
Y en el segundo box que ponga
Nivel: 2

y asi...

Un saludo!

Y disculpen por no saber nada sobre esto