Foros del Web » Programando para Internet » Javascript »

Las operaciones en JavaScript

Estas en el tema de Las operaciones en JavaScript en el foro de Javascript en Foros del Web. Tengo este formulario, que necesito que haga lo que dicen sus cuadros: <form action="prueba" method="get" name="prueba"> tc <input name="tc" type="text" value="1" size="10" maxlength="10">====> Valor ingresado ...
  #1 (permalink)  
Antiguo 01/08/2002, 08:54
 
Fecha de Ingreso: marzo-2002
Mensajes: 99
Antigüedad: 22 años, 10 meses
Puntos: 0
Las operaciones en JavaScript

Tengo este formulario, que necesito que haga lo que dicen sus cuadros:
<form action="prueba" method="get" name="prueba">
tc <input name="tc" type="text" value="1" size="10" maxlength="10">====> Valor ingresado por usuario<br>
valor_1 <input name="v_1" type="text" size="10" maxlength="10" >====> Valor ingresado por usuario<br>
mult <input name="mult" type="text" size="10" maxlength="10" >====> Valor de mult de tc*valor_1<br>
valor_suma <input name="suma" type="text" size="10" maxlength="10" >====> Valor ingresado por usuario<br>
valor_resta <input name="resta" type="text" size="10" maxlength="10" >====> Valor ingresado por usuario<br>
total <input name="total" type="text" size="10" maxlength="10" onBlur="computar(this.form)">====> Valor de la suma de mult+valor_suma-valor_resta
</form>

Favor si alguien me puede ayudar.

Gracias
  #2 (permalink)  
Antiguo 01/08/2002, 08:59
Avatar de Cain  
Fecha de Ingreso: enero-2002
Ubicación: Catalunya
Mensajes: 6.459
Antigüedad: 23 años, 1 mes
Puntos: 17
Re: Las operaciones en JavaScript

Código:
<form action="prueba" method="get" name="prueba">
tc <input name="tc" type="text" value="1" size="10" maxlength="10" onChange="Javascript:document.prueba.mult.value = document.prueba.tc.value * document.prueba.v_1.value";><br>
valor_1 <input name="v_1" type="text" size="10" maxlength="10" onChange="Javascript:document.prueba.mult.value = document.prueba.tc.value * document.prueba.v_1.value";><br>
mult <input name="mult" type="text" size="10" maxlength="10" onChange="Javascript:document.prueba.total.value = document.prueba.mul.value + document.prueba.suma.value - document.prueba.resta.value"><br>
valor_suma <input name="suma" type="text" size="10" maxlength="10" onChange="Javascript:document.prueba.total.value = document.prueba.mul.value + document.prueba.suma.value - document.prueba.resta.value"><br>
valor_resta <input name="resta" type="text" size="10" maxlength="10" onChange="Javascript:document.prueba.total.value = document.prueba.mul.value + document.prueba.suma.value - document.prueba.resta.value"><br>
total <input name="total" type="text" size="10" maxlength="10" onBlur="computar(this.form)"></form>
Ahí está más o menos, podría mejorarse si en lugar de poner los codigos en OnChange, los crearamos una función y en OnChange llamarams a la función.

Joe Tawers,
<a href="http://www.ilimit.com/towers">http://www.ilimit.com/towers</a>
  #3 (permalink)  
Antiguo 01/08/2002, 14:17
 
Fecha de Ingreso: marzo-2002
Mensajes: 99
Antigüedad: 22 años, 10 meses
Puntos: 0
Re: Las operaciones en JavaScript

&lt;script language=&quot;JavaScript&quot;&gt;
&lt;!--
function llenar(){
document.forms[0].total.value = document.forms[0].mult.value + document.forms[0].suma.value - document.forms[0].resta.value;
}
//--&gt;
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action=&quot;prueba&quot; method=&quot;get&quot; name=&quot;prueba&quot;&gt;
tc &lt;input name=&quot;tc&quot; type=&quot;text&quot; value=&quot;1&quot; size=&quot;10&quot; maxlength=&quot;10&quot; onChange=&quot;Javascript:document.prueba.mult.val ue = document.prueba.tc.value * document.prueba.v_1.value&quot;;&gt;&lt;br&gt;
valor_1 &lt;input name=&quot;v_1&quot; type=&quot;text&quot; size=&quot;10&quot; maxlength=&quot;10&quot; onChange=&quot;Javascript:document.prueba.mult.val ue = document.prueba.tc.value * document.prueba.v_1.value&quot;;&gt;&lt;br&gt;
mult &lt;input name=&quot;mult&quot; type=&quot;text&quot; size=&quot;10&quot; maxlength=&quot;10&quot; onChange=&quot;Javascript:document.prueba.mult.val ue = document.prueba.tc.value * document.prueba.v_1.value&quot;; onBlur=&quot;llenar();&quot;&gt;&lt;br&gt;
valor_suma &lt;input name=&quot;suma&quot; type=&quot;text&quot; size=&quot;10&quot; maxlength=&quot;10&quot; onChange=&quot;llenar();&quot;&gt;&lt;br&gt;
valor_resta &lt;input name=&quot;resta&quot; type=&quot;text&quot; size=&quot;10&quot; maxlength=&quot;10&quot; onChange=&quot;llenar();&quot;&gt;&lt;br&gt;
total &lt;input name=&quot;total&quot; type=&quot;text&quot; size=&quot;10&quot; maxlength=&quot;10&quot; &gt;
&lt;/form&gt;

puedes revisar esta funcion, tengo un problema, esta adjuntando los codigos... es decir, al campo total, se adjuntan los campos suma y resta, no los suma o resta, que hago.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:29.