Ver Mensaje Individual
  #1 (permalink)  
Antiguo 02/08/2008, 09:33
anion0x
 
Fecha de Ingreso: junio-2008
Mensajes: 110
Antigüedad: 16 años, 7 meses
Puntos: 0
inconveniente con DOM

Necesito crear algo como esto:

<tr>
<th><label for="modulos">Cantidad de Módulos</label></th>
<td><input class="small" name="modulos" type="text" id="modulos" size="4" maxlength="10"></td>
</tr>

Quiero crearlo desde JS. Y agregarlo a una tabla que tengo. Hice lo siguiente hasta ahora:

Código:
function cantidadElementos(sel) {
	
	var refToSel = sel.name;
		

	if(sel.selectedIndex == 1) {
	
		alert("TEXTO");
		
	} else {
		
		alert("LISTA");
		
		var tabla = document.getElementById("tablastep2");
		
		var row = document.createElement("tr");
		
		var td = document.createElement("td");
		
		var th = document.createElement("th");
		
		var label = document.createElement("label");
		
		label.setAttribute("for", "modulo");
		label.setAttribute("value", "Cant. Modulos");
		
		var input = document.createElement("input");
		input.setAttribute("type","text");
		input.setAttribute("name",'modulo');
		
		

		th.appendChild(label);

		row.appendChild(td);
		
		row.appendChild(th);
		
		td.appendChild(input);
		
		tabla.appendChild(row);		
	}
	
}

Quisiera que se agregue aca:

Código:
         <table name ="tablastep2" id = "tablastep2">
         <?php
			
			for($i = 1; $i <= $_POST['modulos']; $i++) { ?>

          <tr>
            <th><label for="modulo">Módulo <?php echo $i?></label></th>
            <td><select name="modulo<?php echo $i?>" id="modulo<?php echo $i?>" onChange="cantidadElementos(this);">
              <option>Seleccione el tipo de módulo...</option>
              <option value ="1">Texto</option>
              <option>Lista</option>
            </select>
            </td>
          </tr>

			<?php
			}	
			?>

        </table>
El problema que tengo es que no se como seguir, como seteo el valor del label?