Forum de discussion
Forum « Programmation Javascript » (archives)
probleme avec input multi
Envoyé: 21 septembre 2005, 21h50 par melannie
J'aimerais pouvoir faire un multi input mais je comprend rien dans les arrays... Tout fonctionne bien... Sauf l'affichage qui est pas ok...
Merci de votre aide!
Mel
<html>
<head>
<script type="text/javascript">
<!-- Begin
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Husay :: http://www.communitxt.net */
var arrInput = new Array(0);
var arrInputValue = new Array(0);
function addInput() {
//arrInput.push(createInput(arrInput.length));
arrInput.push(arrInput.length);
//arrInputValue.push(arrInputValue.length);
arrInputValue.push("");
display();
}
function display() {
document.getElementById('parah').innerHTML="";
for (intI=0;intI<arrInput.length;intI++) {
document.getElementById('parah').innerHTML+=createInput(arrInput[intI], arrInputValue[intI]);
}
}
function saveValue(intId,strValue) {
arrInputValue[intId]=strValue;
}
function createInput(id,value) {
return "<tr><td><input type='text' name='name"+intI+"' onChange='javascript:saveValue1("+intI+",this.value)' value='"+ value +"'></td><td><input type='text' name='lastname"+intI+"' onChange='javascript:saveValue2("+intI+",this.value)' value='"+ value +"'></td><td><input type='text' name='town"+intI+"' onChange='javascript:saveValue3("+intI+",this.value)' value='"+ value +"'></td></tr>";
}
function deleteInput() {
if (arrInput.length > 0) {
arrInput.pop();
arrInputValue.pop();
}
display();
}
// End -->
</script>
</head>
<body>
<form method="post" action="##" enctype="multipart/form-data">
<table border="1">
<tr>
<td>name</td><td>lastname</td><td>town</td>
</tr>
<tbody id="parah"></tbody>
</table>
<input type="submit" value="GO"><br>
</form>
<a href="javascript:addInput()">Add row</a><br>
</body>
</html>
Réponses
|