Bueno amigo
pcarvajal, he tenido un poco de tiempo libre, y pues me complace ayudarte.
Aqui te dejo "tu codigo" con una pequena modificacion completamente operativo:
Código:
<html>
<head>
<script>
function valida(){
var x=document.frm.cuantos.value;
//deben ser 2 o mas alternativas..
reasigna()
if (x >= 2){
var i;
for (i=1; i<=x; i++){
if(document.getElementById('alternativa_'+i).value==""){
alert("Ingrese la alternativa");
document.getElementById('alternativa_'+i).focus();
return false;
break;
}
alert(document.getElementById('alternativa_'+i).value);
}
}
}
var n=0;
function add() {
n++;
pepe = document.getElementById('tabla');
fila = document.createElement('tr');
fila.id='contenedor'+n;
celda = document.createElement('td');
fila.appendChild(celda);
code=document.createElement('input');
code.type='text';
code.name='alternativa_'+n;
code.id='alternativa_'+n;
code.size='50';
code.maxlength='100';
celda.appendChild(code);
celda = document.createElement('td');
fila.appendChild(celda);
cant=document.createElement('input');
cant.type='button';
cant.value='X';
cant.onclick = function() {del(this.parentNode.parentNode.rowIndex)};
celda.appendChild(cant);
pepe.appendChild(fila);
document.getElementById('cuantos').value = n;
}
function del(obj){
document.getElementById('tabla').deleteRow(obj)
n--;
document.getElementById('cuantos').value = (document.getElementById('cuantos').value-1);
}
function reasigna(){
var d=document;
var inputs=d.frm.getElementsByTagName('input');
var inpTxt= new Array()
var cont=0;
for (m=0; m<inputs.length; m++){
if(inputs[m].type=='text' && inputs[m].name!='cuantos'){
cont=cont+1;
inputs[m].name='alternativa_'+cont;
inputs[m].id='alternativa_'+cont;
}
}
}
</script>
</head>
<body>
<form name="frm">
Total de alternativas:
<input type="text" name="cuantos" id="cuantos" value="0" size="3" readonly>
<input class="boton" type="button" value=" + " onclick="add()">
<table>
<tbody id="tabla"> </tbody>
</table>
<input type="button" value="Validar Alternativas" onclick="valida()">
</form>
</body>
</html>
Quizas no sea una manera muy elegante de hacerlo, pero lo importante en este caso es que funciona.
Te recomiendo que investigues un poco mas, no siempre uno se consigue con quien quiera hacer los codigos por uno.
Saludos!!