problemas al sumar
Espero que alguie me pueda ayudar, tengo un problema al momento de sumar dos campos de texto lo que sucede es que me concatena los valores como le puedo hacer para que me los convierta a valores y no a texto. Gracias de antemano por su ayuda
document.Contratos.totalkm.value = document.Contratos.kmentrada.value-document.Contratos.kmsalida.value
document.Contratos.totxkm.value = document.Contratos.tarxkm.value*document.Contratos.totalkm.value
document.Contratos.subtotal.value = document.Contratos.totxkm.value+document.Contratos.totxhora.value+document.Contratos.totxdia.value+document.Contratos.totxsem.value)
document.Contratos.subtotalgral.value = document.Contratos.subtotal.value+document.Contratos.cargogasolina.value + document.Contratos.dua.value + document.Contratos.servchofer.value + document.Contratos.coveracc.value + document.Contratos.cerodedu.value + document.Contratos.subtotal.value
<td width="175" height="54"><p><strong>COSTO POR KILOMETRO </strong></p>
<p><strong>
<input onChange=calcula() size="10" name="tarxkm">
</strong></p></td>
<td width="126"><p><strong>TOTAL POR KILOMETRO </strong></p>
<p><strong>
<input name="totxkm" type="text" id="totxkm" size="10">
</strong></p></td>
<td width="168" height="54"><p><strong>COSTO POR HORAS </strong></p>
<p><strong>
<input onChange=calcula() size="10" name="tarxhora" >
</strong><strong>
</strong></p></td>
<td width="105"><p><strong>TOTAL POR HORAS </strong></p>
<p><strong>
<input name="totxhora" type="text" id="totxhora" size="10">
</strong></p></td>
<td width="175" height="54"><p><strong>COSTO POR DIAS </strong></p>
<p><strong>
<input onChange=calcula() size="10" name="tarxdia" >
</strong></p></td>
<td width="190"><p><strong>TOTAL POR DIA </strong></p>
<p><strong>
<input name="totxdia" type="text" id="totxdia" size="10">
</strong></p></td>
</tr>
<tr valign="top">
<td height="54"><p><strong>COSTO POR SEMANA </strong></p>
<p><strong>
<input size="10" name="tarxsem" >
</strong></p></td>
<td height="54"><p><strong>TOTAL POR SEMANA </strong></p>
<p><strong>
<input onChange=calcula() size="10" name="totxsem" >
</strong></p></td>
<td height="54" colspan="2"> </td>
<td height="54" colspan="2"> </td>
</tr>
<tr valign="top">
<td height="54" colspan="4"><p class="Estilo1">SUBTOTAL</p>
<p class="Estilo1"><strong>
<input name="subtotal" type="text" id="subtotal" size="15">
</strong></p></td>
<td height="54"> </td>
<td height="54"> </td>
</tr>
<tr valign="top">
<td height="54"><p><strong>CARGO ENTRE CIUDADES(DROP OFF) </strong></p>
<p><span class="Estilo1"><strong>
<input onChange=calcula() size="15" name="dropoff" >
</strong></span></p></td>
<td height="54"><p><strong>CARGO POR GASOLINAS</strong></p>
<p><span class="Estilo1"><strong>
<input onChange=calcula() size="15" name="cargogasolina" >
</strong></span></p></td>
<td height="54"><p><strong>D U A</strong></p>
<p><span class="Estilo1"><strong>
<input onChange=calcula() size="15" name="dua" >
</strong></span></p></td>
<td height="54"><p><strong>SERVICIO DE CHOFER</strong></p>
<p><span class="Estilo1"><strong>
<input onChange=calcula() size="15" name="servchofer" >
</strong></span></p></td>
<td height="54"><p><strong>COBERTURA ACC. PERSONALE0S </strong></p>
<p><span class="Estilo1"><strong>
<input onChange=calcula() size="15" name="coveracc" >
</strong></span></p></td>
<td height="54"><p><strong>CERO DEDUCIBLE</strong></p>
<p><span class="Estilo1"><strong>
<input onChange=calcula() size="15" name="cerodedu" >
</strong></span></p></td>
</tr>
<tr valign="top">
<td height="54"><p class="Estilo1">SUBTOTAL</p>
<p class="Estilo1"><strong>
<strong>
<input size="15" name="subtotalgral" >
</strong> </strong></p></td>
document.Contratos.totalkm.value = document.Contratos.kmentrada.value-document.Contratos.kmsalida.value
document.Contratos.totxkm.value = document.Contratos.tarxkm.value*document.Contratos.totalkm.value
document.Contratos.subtotal.value = document.Contratos.totxkm.value+document.Contratos.totxhora.value+document.Contratos.totxdia.value+document.Contratos.totxsem.value)
document.Contratos.subtotalgral.value = document.Contratos.subtotal.value+document.Contratos.cargogasolina.value + document.Contratos.dua.value + document.Contratos.servchofer.value + document.Contratos.coveracc.value + document.Contratos.cerodedu.value + document.Contratos.subtotal.value
<td width="175" height="54"><p><strong>COSTO POR KILOMETRO </strong></p>
<p><strong>
<input onChange=calcula() size="10" name="tarxkm">
</strong></p></td>
<td width="126"><p><strong>TOTAL POR KILOMETRO </strong></p>
<p><strong>
<input name="totxkm" type="text" id="totxkm" size="10">
</strong></p></td>
<td width="168" height="54"><p><strong>COSTO POR HORAS </strong></p>
<p><strong>
<input onChange=calcula() size="10" name="tarxhora" >
</strong><strong>
</strong></p></td>
<td width="105"><p><strong>TOTAL POR HORAS </strong></p>
<p><strong>
<input name="totxhora" type="text" id="totxhora" size="10">
</strong></p></td>
<td width="175" height="54"><p><strong>COSTO POR DIAS </strong></p>
<p><strong>
<input onChange=calcula() size="10" name="tarxdia" >
</strong></p></td>
<td width="190"><p><strong>TOTAL POR DIA </strong></p>
<p><strong>
<input name="totxdia" type="text" id="totxdia" size="10">
</strong></p></td>
</tr>
<tr valign="top">
<td height="54"><p><strong>COSTO POR SEMANA </strong></p>
<p><strong>
<input size="10" name="tarxsem" >
</strong></p></td>
<td height="54"><p><strong>TOTAL POR SEMANA </strong></p>
<p><strong>
<input onChange=calcula() size="10" name="totxsem" >
</strong></p></td>
<td height="54" colspan="2"> </td>
<td height="54" colspan="2"> </td>
</tr>
<tr valign="top">
<td height="54" colspan="4"><p class="Estilo1">SUBTOTAL</p>
<p class="Estilo1"><strong>
<input name="subtotal" type="text" id="subtotal" size="15">
</strong></p></td>
<td height="54"> </td>
<td height="54"> </td>
</tr>
<tr valign="top">
<td height="54"><p><strong>CARGO ENTRE CIUDADES(DROP OFF) </strong></p>
<p><span class="Estilo1"><strong>
<input onChange=calcula() size="15" name="dropoff" >
</strong></span></p></td>
<td height="54"><p><strong>CARGO POR GASOLINAS</strong></p>
<p><span class="Estilo1"><strong>
<input onChange=calcula() size="15" name="cargogasolina" >
</strong></span></p></td>
<td height="54"><p><strong>D U A</strong></p>
<p><span class="Estilo1"><strong>
<input onChange=calcula() size="15" name="dua" >
</strong></span></p></td>
<td height="54"><p><strong>SERVICIO DE CHOFER</strong></p>
<p><span class="Estilo1"><strong>
<input onChange=calcula() size="15" name="servchofer" >
</strong></span></p></td>
<td height="54"><p><strong>COBERTURA ACC. PERSONALE0S </strong></p>
<p><span class="Estilo1"><strong>
<input onChange=calcula() size="15" name="coveracc" >
</strong></span></p></td>
<td height="54"><p><strong>CERO DEDUCIBLE</strong></p>
<p><span class="Estilo1"><strong>
<input onChange=calcula() size="15" name="cerodedu" >
</strong></span></p></td>
</tr>
<tr valign="top">
<td height="54"><p class="Estilo1">SUBTOTAL</p>
<p class="Estilo1"><strong>
<strong>
<input size="15" name="subtotalgral" >
</strong> </strong></p></td>
Efectivamente, si haces '+ ' con dos campos de texto lo que hace es concatenartelos, para poder sumarlos los tienes que parsear a enteros, por ejemplo::
var val1 = parseInt(document.Contratos.kmentrada.value)
var val2 = parseInt(document.Contratos.kmentrada.value);
var val 3= va1 - val2
var val1 = parseInt(document.Contratos.kmentrada.value)
var val2 = parseInt(document.Contratos.kmentrada.value);
var val 3= va1 - val2
Javi y como le regreso el valor a resultante a un campo de texto, es decir, val3=val1-val2; pero quiero que val3 me lo mueste en pantalla como resultado, probe con la siguiente operacion document.Contratos.totalkm.value=val3;
pero no funciono me podrias decir en que estoy mal
Gracias nuevamente
pero no funciono me podrias decir en que estoy mal
Gracias nuevamente