Foros del Web » Programando para Internet » Javascript »

Problema con codigo en IE

Estas en el tema de Problema con codigo en IE en el foro de Javascript en Foros del Web. Hola el siguiente codigo funciona perfecto en Mozilla Firefox, pero en internet explorer no funciona parte de la aplicacion. El script crea elementos table, input, ...
  #1 (permalink)  
Antiguo 19/10/2006, 19:32
 
Fecha de Ingreso: noviembre-2003
Mensajes: 798
Antigüedad: 20 años, 5 meses
Puntos: 8
Problema con codigo en IE

Hola el siguiente codigo funciona perfecto en Mozilla Firefox, pero
en internet explorer no funciona parte de la aplicacion.

El script crea elementos table, input, etc dinamicamente, y ademas hace la suma en los campos input Bruto y Retencion y el resultado lo deja en el campo liquido (calculo el cual no funciona en IE).

Código PHP:
<html>
<
head>
<
STYLE>
#testlayer {
      
positionabsolute;
   
background#732264;
   
color#ffffff;
   
font16px arial,helvetica;
   
top: -120px/* hide it on load */
   
z-index3;
}

</
STYLE>
   <
script type="text/javascript">
    var 
rowNumber 1;
    function 
delRow(buttonTable)
    {
      var 
row button.parentNode.parentNode;
      var 
tbody document.getElementById(Table).getElementsByTagName('tbody')[0];
      
tbody.removeChild(row);
    }

/**************************************************************/
function Suma(CantidadBrutoRetencionLiquidoLiquidosimporte)
{
    var 
Valor1 parseInt(document.getElementById(Cantidad).value);
    var 
Valor2 parseInt(document.getElementById(Liquido).value);
    var 
Valor3 0.9;
    
    
document.getElementById(Liquidosimporte).value parseInt((Valor1*Valor2));
    
document.getElementById(Bruto).value parseInt(((Valor1*Valor2)/Valor3));
    
document.getElementById(Retencion).value = (parseInt(((Valor1*Valor2)/Valor3))-(Valor1*Valor2));
}

    function 
addRow(Table)
    {  

      var 
aTable document.getElementById(Table)
      
aTable.setAttribute("name",Table);
      
aTable.setAttribute("border",0);
      var 
tbody document.getElementById(Table).getElementsByTagName('tbody')[0];
      
tbody.setAttribute('name','TableBody');

      var 
row document.createElement('TR');
      var 
cells = Array();
      var 
inp = Array();
      
      for (
1i<9i++){
         
cells[i] =  document.createElement('td');
         
inp[i] = document.createElement('input');

      }
      
cells[2].setAttribute('width','10px');

      
inp[1] = document.createTextNode(rowNumber);

      
inp[2].setAttribute('type','text');
      
inp[2].setAttribute('name','cantidad['+rowNumber+']');
      
inp[2].setAttribute('id','cantidad['+rowNumber+']');
      
inp[2].setAttribute('size','4');
      
inp[2].setAttribute('maxlength','4');
      
inp[2].setAttribute('value','1');
      
inp[2].setAttribute("onKeyUp","Suma('cantidad["+rowNumber+"]', 'bruto["+rowNumber+"]', 'retencion["+rowNumber+"]', 'liquido["+rowNumber+"]', 'liquidosimporte["+rowNumber+"]')");
      
inp[2].setAttribute('autocomplete','OFF');
      
      
inp[3].setAttribute('type','text');
      
inp[3].setAttribute('name','item['+rowNumber+']');
      
inp[3].setAttribute('id','item['+rowNumber+']');
      
inp[3].setAttribute('size','20');
      
inp[3].setAttribute('maxlength','20');
      
inp[3].setAttribute('value','');
      
inp[3].setAttribute('autocomplete','OFF');      

      
inp[4].setAttribute('type','text');
      
inp[4].setAttribute('name','liquido['+rowNumber+']');
      
inp[4].setAttribute('id','liquido['+rowNumber+']');
      
inp[4].setAttribute('size','10');
      
inp[4].setAttribute('maxlength','20');
      
inp[4].setAttribute('value','0');
      
inp[4].setAttribute("onKeyUp","Suma('cantidad["+rowNumber+"]', 'bruto["+rowNumber+"]', 'retencion["+rowNumber+"]', 'liquido["+rowNumber+"]', 'liquidosimporte["+rowNumber+"]')");
      
inp[4].setAttribute('autocomplete','OFF');
      
      
inp[5].setAttribute('type','text');
      
inp[5].setAttribute('name','liquidosimporte['+rowNumber+']');
      
inp[5].setAttribute('id','liquidosimporte['+rowNumber+']');
      
inp[5].setAttribute('size','10');
      
inp[5].setAttribute('maxlength','20');
      
inp[5].setAttribute('value','');
      
inp[5].setAttribute('autocomplete','OFF');
      
      
inp[6].setAttribute('type','text');
      
inp[6].setAttribute('name','retencion['+rowNumber+']');
      
inp[6].setAttribute('id','retencion['+rowNumber+']');
      
inp[6].setAttribute('size','10');
      
inp[6].setAttribute('maxlength','20');
      
inp[6].setAttribute('value','');
      
//inp[6].setAttribute('disabled','true');
      
inp[6].setAttribute('autocomplete','OFF');

      
inp[7].setAttribute('type','text');
      
inp[7].setAttribute('name','bruto['+rowNumber+']');
      
inp[7].setAttribute('id','bruto['+rowNumber+']');
      
inp[7].setAttribute('size','10');
      
inp[7].setAttribute('maxlength','20');
      
inp[7].setAttribute('value','');
      
//inp[7].setAttribute('disabled','true');
      
inp[7].setAttribute('autocomplete','OFF');
      
      
// remove and Add row buttons
      
inp[8].setAttribute('type','image');
      
inp[8].setAttribute('name','RemoveRow.' rowNumber '.13');
      
inp[8].setAttribute('src','minus.jpg');
      
inp[8].onclick=function(){delRow(thisTable);}

      for (
1i<9i++){
        
cells[i].appendChild(inp[i]);
        
row.appendChild(cells[i]);
      }
      
rowNumber++;
      
tbody.appendChild(row);
    }

  
</script>
</head>
<body>

<form name=Form1 action="index.php" method="post">

<table border="0" id="table1" name="table1">
<input type="button" value="Add Row to table 1" onClick="addRow('table1');">
  <tr>
    <td><b>Número Linea</b></td>
    <td><b>Cantidad</b></td>
    <td><b>Item</b></td>
    <td><b>Liquido</b></td>
    <td><b>Liquido Importe</b></td>
    <td><b>Retención</b></td>
    <td><b>Bruto</b></td>
  </tr>
</table>

<input type="submit" value="Add" name="add" >
</form>
</body>
</html> 
gracias

Última edición por zsamer; 19/10/2006 a las 21:17
  #2 (permalink)  
Antiguo 20/10/2006, 09:36
 
Fecha de Ingreso: noviembre-2003
Mensajes: 798
Antigüedad: 20 años, 5 meses
Puntos: 8
necesito que algun alma caricativa me ayude a ver el codigo para que funcione en IE.

SALUDOS
  #3 (permalink)  
Antiguo 20/10/2006, 10:17
 
Fecha de Ingreso: octubre-2006
Mensajes: 24
Antigüedad: 17 años, 7 meses
Puntos: 0
Hola, en internet explorer no acepta los eventos, es solo cuestion de que llames a la funcion de la siguiente forma:
Código:
<input type="button" value="Add Row to table 1" onClick="window.addRow('table1');">
con eso te debe funcionar, saludos
  #4 (permalink)  
Antiguo 20/10/2006, 10:35
 
Fecha de Ingreso: noviembre-2003
Mensajes: 798
Antigüedad: 20 años, 5 meses
Puntos: 8
hola zero01, gracias por responder, estube viendo tu solución pero sigue igual.
en todo caso el problema no es en la funcion addRow(), IE agrega las filas sin problema, el problemon es cuando quiero hacer los calculos en los imputs de la fila, en el fondo lo que no me funciona en Internet explorer es la función Suma().

Gracias y saludos
  #5 (permalink)  
Antiguo 09/11/2006, 11:09
 
Fecha de Ingreso: octubre-2006
Mensajes: 2
Antigüedad: 17 años, 6 meses
Puntos: 0
Solución setAttribute

Hola viejo zsamer

Yo también tenía ese problema con la chafa de IE con javaScript, probá con el siguiente código

en vez de darle:

objeto.setAttribute("onKeyUp","Suma()");

dale este otro

objeto.onkeyup = function(){ Suma(); };
^
ojo con las minúsculas

Espero que te funcione
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 15:14.