JavaScript - Problemas de suma en js

 
Vista:
sin imagen de perfil

Problemas de suma en js

Publicado por Andrea (1 intervención) el 28/10/2015 19:54:58
Hola amigos, espero que me puedan ayudar con mi problema, tengo un formulario hecho en php, y tengo una función en js donde voy sumando las cantidades, pero al realizar la validación para que se muestre el total con punto (ej: 10.000) no me realiza la suma. Muestro el código

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<form id="form1" name="form1" method="post" action="test.php">
<table width="200" border="0">
  <tr>
    <td>Fono</td>
    <td><input number  name="fono" type="text" id="fono" value="<? if($pdata['fono']!=""){ echo $pdata['fono'];}else{ echo "0";}?>" /></td>
 
  </tr>
  <tr>
    <td>Cable</td>
    <td><input  name="cable" type="text" id="cable"  value="<? if($pdata['cable']!=""){ echo $pdata['cable'];}else{ echo "0";}?>" /></td>
 
  </tr>
  <tr>
    <td>Comida</td>
    <td><input  number name="food" type="text" id="food"  value="<? if($pdata['food']!=""){ echo $pdata['food'];}else{ echo "0";}?>" /></td>
 
  </tr>
<tr>
    <td>Total</td>
    <td><input number  name="tot" type="text" id="tot"  value="<? if($pdata['tot']!=""){ echo $pdata['tot'];}else{ echo "0";}?>" /></td>
 
  </tr>
</table>
</form>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<script language="javascript" src="/function.js"></script>
<script src="jquery-1.8.3.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="jquery.number.js"></script>
<script language="javascript1.2">
function validar(nombre){
    param=document.getElementById(nombre);
    if(param.value.indexOf(".")==-1){
        totalMensual();
    }else{
        alert("Ingrese el monto sin puntos ni comas, solo numeros.");
        param.value=0;
        totalMensual();
        param.focus();
    }
}
 
function totalMensual(){
    param=document.getElementById('fono').value;
    param1=document.getElementById('cable').value;
    param2=document.getElementById('food').value;
    document.getElementById(tot).value=eval(param)+eval(param1)+eval(param2);
 
}
 
$(document).ready(function (){
    $('input[number]').number( true, 0, ",", "." );
});
</script>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder