Ver Mensaje Individual
  #3 (permalink)  
Antiguo 08/02/2008, 12:10
alexisfch
 
Fecha de Ingreso: septiembre-2007
Mensajes: 150
Antigüedad: 16 años, 7 meses
Puntos: 1
De acuerdo Re: Resultado en textfield

hola, prueba con esto, con este codigo podras multiplicar por un numero definido en otro textbox , el cual no se puede modificar, a la vez le agregue un script para que no pueda ingresar nada mas que numero en el text box.

Código HTML:
<html> 
<head> 
    <title>multiplicador</title>
</head>

<script language="javascript">
function solonumeros(){
var key=window.event.keyCode;
if (key < 48 || key > 57){
window.event.keyCode=0;
}}
</script>
<script language="javascript">
function solonumeros(){
var key=window.event.keyCode;
if (key < 48 || key > 57){
window.event.keyCode=0;
}}
</script>

<script type="text/javascript"> 
function Sum2(){ 
      inter2 = setInterval("operar2()",1); 
} 
function operar2(){ 
      uno = document.frm.numero1.value; 
      dos = document.frm.numero2.value; 
      document.frm.total.value = uno * dos; 
} 
function NoSum2(){ 
      clearInterval(inter2); 
} 
</script>
</script>
<body>
<form name="frm">
  <table width="143" border="1">
    
    <tr>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td width="133"><table width="133" border="1">
        <tr>
          <td width="35" height="26"><strong>numero1</strong></td>
          <td><input name="numero1" style="text-align:right; background-color:#CCCCCC" type=text onFocus="Sum2();" onBlur="NoSum2();" id="numero1" onKeyPress="solonumeros()" size="7" maxlength="8">
            <input name="numero2b" type=text id="numero2b" style="border-width: 1px; border-style: solid; font-size:1pt; color: #ffffff; letter-spacing : 1px" onFocus="Sum();" onBlur="NoSum();" onKeyPress="solonumeros()" size="1"></td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td><table width="133" border="1">
        <tr>
          <td width="35"><strong>numero2</strong></td>
          <td><input name="numero2" type="text" style="text-align:right" value="22" readonly="readonly" size="7">
            <input name="dec" style="border-width: 1px; border-style: solid; font-size:1pt; color: #ffffff; letter-spacing : 1px" type="text" size="1"></td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td><table width="133" border="1">
        <tr>
          <td width="35"><strong>Total</strong></td>
          <td><input name="total" style="text-align:right" type=text id="total" size="7"></td>
        </tr>
      </table></td>
    </tr>
  </table>
  <label></label>
</form>
 
</body> 
</html> 
en este otro no se ve el campo con el numero que deseas multiplicar:
Código HTML:
<html> 
<head> 
    <title>multiplicador</title>
</head>

<script language="javascript">
function solonumeros(){
var key=window.event.keyCode;
if (key < 48 || key > 57){
window.event.keyCode=0;
}}
</script>
<script language="javascript">
function solonumeros(){
var key=window.event.keyCode;
if (key < 48 || key > 57){
window.event.keyCode=0;
}}
</script>

<script type="text/javascript"> 
function Sum2(){ 
      inter2 = setInterval("operar2()",1); 
} 
function operar2(){ 
      uno = document.frm.numero1.value; 
      document.frm.total.value = uno * 22; 
} 
function NoSum2(){ 
      clearInterval(inter2); 
} 
</script>
</script>
<body>
<form name="frm">
  <table width="143" border="1">
    
    <tr>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td width="133"><table width="133" border="1">
        <tr>
          <td width="35" height="26"><strong>numero1</strong></td>
          <td><input name="numero1" style="text-align:right; background-color:#CCCCCC" type=text onFocus="Sum2();" onBlur="NoSum2();" id="numero1" onKeyPress="solonumeros()" size="7" maxlength="8">
            <input name="numero2b" type=text id="numero2b" style="border-width: 1px; border-style: solid; font-size:1pt; color: #ffffff; letter-spacing : 1px" onFocus="Sum();" onBlur="NoSum();" onKeyPress="solonumeros()" size="1"></td>
        </tr>
      </table></td>
    </tr>
    
    <tr>
      <td><table width="133" border="1">
        <tr>
          <td width="35"><strong>Total</strong></td>
          <td><input name="total" style="text-align:right" type=text id="total" size="7"></td>
        </tr>
      </table></td>
    </tr>
  </table>
  <label></label>
</form>
 
</body> 
</html> 
Código HTML:
document.frm.total.value = uno * 22;
22 fue el numero que use para multiplicar, cambialo por el que quieras.

Saludos