Ver Mensaje Individual
  #3 (permalink)  
Antiguo 19/05/2009, 12:11
Avatar de educlon
educlon
 
Fecha de Ingreso: octubre-2003
Ubicación: Buenos Aires
Mensajes: 35
Antigüedad: 20 años, 7 meses
Puntos: 0
Respuesta: onChange en filas dinámicas no funciona

Excelente, muchas gracias ZEROKILLED, hice lo que me comentaste y funcionó, la verdad no sabía que no se podía usar el índice en este caso. Voy a investigar mas este asunto. Para el que lo desee, dejo el codigo completo con tres items de menu:

Código javascript:
Ver original
  1. var indiceFilaForm=1;
  2. function agregarProducto()
  3. {
  4.     myNewRow = document.getElementById("tablaProducto").insertRow(-1);
  5.     myNewRow.id=indiceFilaForm;
  6.     myNewCell=myNewRow.insertCell(-1);
  7.     myNewCell.innerHTML="<select name='vid_producto_"+indiceFilaForm+"' onchange='cambia_precio("+indiceFilaForm+")' ><option value=1>AirLink - PCI AIR LINK N (u$s 45.00)</option><option value=2>American Tourister - FUNDAS TELA AVION (u$s 8.00)</option><option value=3>Case Logic - CASE LOGIC (u$s 36.00)</option></select>";
  8.     myNewCell=myNewRow.insertCell(-1);
  9.     myNewCell.innerHTML="Cant.<input type=text name='vcantidad_"+indiceFilaForm+"' size='3' value='1' style='text-align:center;' />";
  10.     myNewCell=myNewRow.insertCell(-1);
  11.     myNewCell.innerHTML="u$s<input type=text name='vprecio_"+indiceFilaForm+"' id='vprecio' size='6' style='text-align:right;' />";
  12.     myNewCell=myNewRow.insertCell(-1);
  13.     myNewCell.innerHTML="<input type='button'  value='Quitar' onclick='quitarProducto(this)'>";
  14.     myNewCell=myNewRow.insertCell(-1);
  15.     myNewCell.innerHTML="";
  16.     myNewCell=myNewRow.insertCell(-1);
  17.     myNewCell.innerHTML="";
  18.     indiceFilaForm++;
  19. }
  20.  
  21. function quitarProducto(obj)
  22. {
  23.     var oTr = obj;
  24.     while(oTr.nodeName.toLowerCase()!='tr')
  25.     {
  26.         oTr=oTr.parentNode;
  27.     }
  28.     var root = oTr.parentNode;
  29.     root.removeChild(oTr);
  30. }
  31.  
  32. // Precios de los productos
  33.  
  34. var precio_1="23.00";
  35. var precio_2="120.00";
  36. var precio_3="54.00";
  37.  
  38. function cambia_precio(indice)
  39. {
  40.     var id_producto;
  41.     id_producto = document.f1['vid_producto_' + indice][document.f1['vid_producto_' + indice].selectedIndex].value;
  42.     if (id_producto != "")
  43.     {
  44.         mi_precio = eval("precio_" + id_producto);
  45.         document.f1['vprecio_' + indice].value = mi_precio;
  46.         document.f1['vprecio_' + indice].text = mi_precio;
  47.     }
  48.     else
  49.     {
  50.         document.f1['vprecio_' + indice].value = "";
  51.         document.f1['vprecio_' + indice].text = "";
  52.     }
  53. }


Código HTML:
<table>
<tr class="tablerow1">
	<td width="10%"><b>Articulos</b></td>
	<td width="90%">
		<table cellpadding='3' cellspacing='3' style='border:#999999' id="tablaProducto">
			<tr bgColor='#CCCCCC'></tr>
		</table>
		<input type="button" onClick="agregarProducto()" value="Agregar Producto" >
	</td>
</tr>
<table> 
Espero que les sirva

Mil gracias y saludos...

Eduardo