Ver Mensaje Individual
  #7 (permalink)  
Antiguo 16/03/2012, 15:29
Avatar de IsaBelM
IsaBelM
Colaborador
 
Fecha de Ingreso: junio-2008
Mensajes: 5.032
Antigüedad: 15 años, 10 meses
Puntos: 1012
Respuesta: el número de inputs que existe siempre coincide con un número.

entonces se complica un poco mas
Cita:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function crearCampos(cantidad){
var div = document.getElementById('campos_dinamicos');
nuevosNodos = cantidad - div.childNodes.length;
asignarId = div.childNodes.length;

if(nuevosNodos >= 1) {

for(var i = 1; i <= nuevosNodos; i++){

var salto = document.createElement('p');
var input = document.createElement('input');
var text = document.createTextNode('Campo Dinamico ' + ++asignarId + ': ');
input.setAttribute('type', 'text');
input.setAttribute('name', 'campo[]');
input.setAttribute('id', 'campo' + asignarId);
input.setAttribute('size', '12');
input.className = 'input';
salto.appendChild(text);
salto.appendChild(input);
div.appendChild(salto);
}
} else {

while(nuevosNodos <= -1) {

div.removeChild(div.lastChild);
nuevosNodos++;
}

}
}
</script>
</head>
<body>
<form>
¿Cuantos Campos? <input type="text" name="cantidad" id="cantidad" value="" onkeyup="if(this.value != '') {crearCampos(this.value);}" />
<div id="campos_dinamicos"></div>
</form>
</body>
</html>
__________________
if(ViolenciaDeGénero) {alert('MUJER ASESINADA');}