Bonjour à tous,
j'ai trouvé un petit scrit qui me permet d'ajouter des inputs à mon formulaire.
Actuelement un lien est généré à coté des input créés.
Tous marche bien, mais j'aimerais avoir un seul Bouton pour suprimés les inputs 1 par 1.
J'ai bien trouvé quelque bidouillage, mais rien de concluant.
Voici mon code :
<html><head><title>Test</title>
<script type="text/javascript">
<!--
function removeInput(num){
var inputFile = document.getElementById('choix'+num);
var removeLink = document.getElementById('removeInput'+num);
var br = document.getElementById('br'+num);
document.getElementById('choix').removeChild(inputFile);
document.getElementById('choix').removeChild(removeLink);
document.getElementById('choix').removeChild(br);
}
function addInput(num){
var input = document.createElement("input" );
input.setAttribute("type", "text" );
input.setAttribute("name", "choix" + num);
input.setAttribute("id", "choix" + num);
var br = document.createElement("br" );
br.setAttribute("id", "br" + num);
var removeLink = document.createElement("a" ); //lien pour supprimer l element
removeLink.setAttribute("onclick", "removeInput("+num+" )" )
removeLink.setAttribute("href", "#documents" )
removeLink.setAttribute("id", "removeInput"+num)
removeLink.appendChild(document.createTextNode('Supprimer'));
document.getElementById('choix').appendChild(br);
document.getElementById('choix').appendChild(input);
document.getElementById('choix').appendChild(removeLink);
var link = document.getElementById('addInputFile');
num = num+1;
link.setAttribute("onclick", "addInput("+num+" )" );
}
//-->
</script></head>
<body>
<a href="#" onClick="addInput(1)" id="addInputLink">Ajouter un document</a>
<div anchor="documents">
<span>Joindre documents</span>
<br/>
<div id="choix" name="linkedFiles">
<input type="text" name="rep1" />
</div>
</div>
</body></html>
Merci de votre aide
