Ver Mensaje Individual
  #3 (permalink)  
Antiguo 06/05/2012, 04:53
Frannixo
 
Fecha de Ingreso: abril-2012
Mensajes: 87
Antigüedad: 12 años
Puntos: 1
Respuesta: Convertidor con javascript y ajax

Esto es un prueba de lo que quiero hacer

JavaScript:

Código Javascript:
Ver original
  1. function CambiarDersus()
  2. {
  3.     var vp;
  4.         var maximo;
  5.         var heroes;
  6.         maximo=document.forms['cambiar'].maximo.value;
  7.         if (isNaN(document.forms['cambiar'].amount.value))
  8.         {
  9.             document.forms['cambiar'].amount.value.focus();
  10.             return false;
  11.         }
  12.         if(document.forms['cambiar'].amount<=0)
  13.         {
  14.            alert("Error:\nIntroduzca una cantidad.");
  15.            document.forms['cambiar'].amount.value.focus();
  16.            return false;
  17.         }
  18.     vp=document.forms['cambiar'].amount.value;
  19.    
  20.     heroes=vp * 2;
  21.         if(heroes>maximo * 2)
  22.         {
  23.             heroes=maximo * 2;
  24.         }
  25.     document.forms['cambiar'].heroes.value=heroes;
  26. }


Formulario:

Código HTML:
Ver original
  1. <form name="cambiar" method="POST" action="" autocomplete="off">
  2. <center>
  3.     <div style="max-width:250px; max-height:250px; background-color:#e7e7e7; text-align:center; border-radius:5px; -moz-border-radius:5px; -webkit-border-radius:5px; box-shadow: 0 0 6px #333; -moz-box-shadow: 0 0 6px #333; -webkit-box-shadow: 0 0 6px #333;"><br><br>
  4.         Perder&aacute;s:
  5.         <input style="max-width:40px; border-style:solid; border-width:1px; border-color:#999; text-align:right;" type="text" id="vpamount" name="amount" value="0" onKeyUp="javascript:CambiarDersus();" onFocus="if (this.value=='0') this.value='';"></input>
  6.         <span><img src="wow/static/images/shop/votes.png" height="15" width="15" style=""></img></span><br>
  7.         <input type="hidden" name="maximo" value="0"></input>
  8.         Recibir&aacute;s:
  9.         <input style="max-width:40px; background-color:transparent; border-style:none; text-align:right;" type="text" name="heroes" value="0" readonly></input>
  10.         <span><img src="wow/static/images/shop/titanio.png" height="15" width="15" style=""></img></span><br><br><br>
  11.     </div><br><br>
  12.     <input type="submit" name="Convertir" value="Cambiar">
  13. </center>
  14. </form>