Ver Mensaje Individual
  #2 (permalink)  
Antiguo 10/07/2013, 10:50
jonny03
 
Fecha de Ingreso: julio-2013
Mensajes: 4
Antigüedad: 10 años, 8 meses
Puntos: 0
Respuesta: Calcular la suma de dos campos de texto sin boton

Parece que ya e logrado hacerlo funcionar yo solo
me quedo algo así:
Código HTML:
<html>
<head>
<title>Calculador de productos</title>
<script>
function cambia1(form1){
if(document.form1.dis[0].selected == true){
document.form1.cos_dis.value="0";
}
if(document.form1.dis[1].selected == true){
document.form1.cos_dis.value="5";
}
if(document.form1.dis[2].selected == true){
document.form1.cos_dis.value="10";
}
}
function cambia2(form1){
if(document.form1.pap[0].selected == true){
document.form1.cos_pap.value="0";
}
if(document.form1.pap[1].selected == true){
document.form1.cos_pap.value="2";
}
if(document.form1.pap[2].selected == true){
document.form1.cos_pap.value="7";
}
if(document.form1.pap[3].selected == true){
document.form1.cos_pap.value="2";
}
}
</script>
</head>

<body><form id="form1" name="form1" method="post" action="">
<table width="414" border="2">
  <tr>
    <th width="90" rowspan="2" scope="col">&nbsp;</th>
    <th width="82" scope="col">Discos</th>
    <th width="86" scope="col">Papeleria</th>
  </tr>
  <tr>
    <td><center>
      <select name="dis" id="dis" onchange="cambia1(), calcula('+')">
  <option value="0">Ninguno</option>
  <option value="5">CD</option>
  <option value="10">DVD</option>
      </select></center></td>
    <td><center>
        <select name="pap" id="pap"onchange="cambia2(), calcula('+')">
<option value="0">Ninguno</option>
<option value="2">Lapiz</option>
<option value="7">Pluma</option>
<option value="2">Borrador</option>
        </select>
    </center></td>
    <td width="126"><div align="center"><strong>Total:</strong></div></td>
  </tr>
  <tr>
    <td height="26"><strong>Costo:</strong></td>
    <td>
      $
      <input name="cos_dis" type="text" id="cos_dis" value="0" size="3" readonly/>
    </td>
    <td>
      $
      <input name="cos_pap" type="text" id="cos_pap" value="0" size="3" readonly contenteditable="false"/>
    </td>
    <td>
      $
      <input name="total_cos" type="text" id="total_cos" value="0" size="5" readonly/>
</td>
  </tr>
</table></form>
<script language="javascript">  
function calcula(operacion){  
    var dis = document.form1.cos_dis.value; 
    var pap = document.form1.cos_pap.value; 
    var result = eval(dis + operacion + pap); 
    document.form1.total_cos.value = result ; 
}
</script>
</body>
</html> 
Gracias de cualquier forma a cualquiera que me haya querido ayudar