![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
20/12/2007, 07:08
|
![Avatar de agressor](http://static.forosdelweb.com/customavatars/avatar203215_1.gif) | | | Fecha de Ingreso: noviembre-2007 Ubicación: Knocking the Death Door..
Mensajes: 368
Antigüedad: 17 años, 2 meses Puntos: 3 | |
Re: Sumar valores de campos en formulario Espero te sirva..
<script language="javascript">
function addTotals() {
with (document.forms["f1"])
{
var totalResult = Number( one.value ) + Number( two.value )+ Number( three.value )+ Number( four.value );
total.value = roundTo( totalResult, 2 );
}
}
function roundTo(num,pow){
if( isNaN( num ) )
{
num = 0;
}
num *= Math.pow(10,pow);
num = (Math.round(num)/Math.pow(10,pow))+ "" ;
if(num.indexOf(".") == -1)
num += "." ;
while(num.length - num.indexOf(".") - 1 < pow)
num += "0" ;
return "$"+num;
}
</script>
<form name="f1">
<p>
<select size="1" style="width:140px;font-size:10px;font-family:Verdana, Arial, Helvetica, sans-serif;font-weight:bold;color:#000000;background-color:#FFFFFF" name='one'>
<option value='0'> # Adultos
<option value='2183'> 1
<option value='4366'> 2
</select>
<br>
<select size="1" style="width:140px;font-size:10px;font-family:Verdana, Arial, Helvetica, sans-serif;font-weight:bold;color:#000000;background-color:#FFFFFF" name='two'>
<option value='0'> # 4 a 11 años
<option value='1308'> 1
<option value='2616'> 2
</select>
<br>
<select size="1" style="width:140px;font-size:10px;font-family:Verdana, Arial, Helvetica, sans-serif;font-weight:bold;color:#000000;background-color:#FFFFFF" name='three'>
<option value='0'> # 2 a 3 años
<option value='551'> 1
<option value='1102'> 2
</select>
<br>
<select size="1" style="width:140px;font-size:10px;font-family:Verdana, Arial, Helvetica, sans-serif;font-weight:bold;color:#000000;background-color:#FFFFFF" name='four'>
<option value='0'> # Single
<option value='4346'> 1
<option value='8692'> 2
</select>
</p>
<p>
<input type="button" name="button" onclick="addTotals()" value="Calcular" style="width:55px;font-size:10px;font-family:Verdana, Arial, Helvetica, sans-serif;font-weight:bold;color:#000000">
<input type="text" name="total" style="width:76px;font-size:10px;font-family:Verdana, Arial, Helvetica, sans-serif;font-weight:bold;color:#000000;background-color:#FFFFFF">
</p>
</form>
salu2..!! |