Código Javascript:
Ver original
function ID(id){ return document.getElementById(id); } var n=1, l=1; function addI(v){ switch(v.value){ case '+7': ID('btn').style.display = 'block'; break; default: if(Int(v.value) > n){ for(j=0; j<Int(v.value)-l; j++){ ID('inicio').innerHTML+="<input type='text' name='coordx[]' id='cx"+n+"' size='10' class='input' /><br />"; ID('final').innerHTML+="<input type='text' name='coordy[]' id='cy"+n+"' size='10' class='input' /><br />"; n++; } } break; } l = ID('inicio').getElementsByTagName('input').length+1; } function addC(){ ID('inicio').innerHTML += "<input type='text' name='coordx[]' id='cx"+n+"' size='10' class='input' /><br />"; ID('final').innerHTML += "<input type='text' name='coordy[]' id='cy"+n+"' size='10' class='input' /><br />" n++; }
Código HTML:
Gracias y saludos (: Ver original
<ul> <li> <select id='colonias' name='colonias' onchange="addI(this);"> </select> </li> <li> <fieldset style='width:20%;' id='f'> <br /> <input type='text' id='cx0' name='coordx[]' size='15'/> <input type='text' id='cy0' name='coordy[]' size='15' /> <br /> <br /> </fieldset> <input type="button" value="Agregar campo" id='btn' onclick="addC();if(ID('inicio').getElementsByTagName('input').length>6) ID('colonias').disabled=true;" /> </li> </ul>