1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| <script type="text/javascript">
var c,c2, ch;
function plus(){
c=document.getElementById("cadre");
c2=c.getElementsByTagName("input");
ch=document.createElement("input");
ch.setAttribute("type","text");
ch.setAttribute("name","ch"+c2.length);
c.appendChild(ch);
document.getElementById("sup").style.display="inline";
}
function moins(b){
if(!c2[1]){
b.style.display="none"
}
if(c2[0]){
c.removeChild(c2[c2.length-1])
}
}
</script>
<form id="frm" action="">
<div id="cadre" style="margin-left:100px;width:200px">
</div>
<p>
<input type="button" value="ajouter un champ" onclick="plus()" />
<input type="button" style="display:none" id="sup" value="supprimer un champ" onclick="moins(this)" />
</p>
</form> |
Partager