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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
<html>
<head>
<title>Tableau dynamique</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
table { border:thin solid #A2968A; border-collapse:collapse; text-align:center; }
td { border:thin dotted #A2968A; padding:5px; text-align:center; height: 50px; }
tr.trSpe { border:thin dotted #A2968A; padding:5px; text-align:center; height: 50px; background-color:#aeaeae; }
td.tdSpe { border:thin dotted #A2968A; padding:5px; text-align:center; height: 50px; background-color:#aeaeae; }
</style>
<script type="text/javascript" language="JavaScript">
function clone(line, index) {
newLine = line.cloneNode(true); //l'option selected des listes déroulantes n'est pas conservée lors du clonage
var oldHtml = newLine.innerHTML;
var reg = new RegExp ("_1_1_2_1", "g");
var newHtml = oldHtml.replace(reg, "_1_1_2_4");
alert(newHtml);
newLine.innerHTML = newHtml;
line.parentNode.appendChild(newLine);
}
function cloneEtVide(line, index) {
newLine = line.cloneNode(true);
alert(line.rowIndex);
alert("Il y avait "+line.parentNode.rows.length+" lignes");
alert("J'ajoute donc une "+(line.parentNode.rows.length + 1)+"e ligne");
var mesInput = newLine.getElementsByTagName('INPUT');
var mesTextarea = newLine.getElementsByTagName('textarea');
var mesSelect = newLine.getElementsByTagName('select');
for (i=0 ; i<= mesInput.length-1 ; i++) { if (mesInput[i].type == 'text') mesInput[i].value=""; }
for (i=0 ; i<= mesTextarea.length-1 ; i++) { mesTextarea[i].innerHTML = ""; }
for (i=0 ; i<= mesSelect.length-1 ; i++) { mesSelect[i].selectedIndex = 0; }
line.parentNode.appendChild(newLine);
alert(newLine.rowIndex);
}
function supprLigne(line) {
line.parentNode.removeChild(line);
}
</script>
</head>
<body>
<table id="table1" border="1" cellspacing="0" cellpadding="0">
<tr id="1" class="trSpe">
<td> <input type="text" value="input text A1" name="_1_1_2_1_3_1" size="16" maxlength="64"></td>
<td> <input type="text" value="_1_1_2_1_4_1" name="_1_1_2_1_4_1" size="16" maxlength="64"></td>
<td> <TEXTAREA WRAP="soft" name="_1_1_2_1_5_1" ROWS="2" COLS="16">textarea A2</TEXTAREA></td>
<td> <select name="_1_1_2_1_6_1"><OPTION value="">--<OPTION value="option 1">A3-1<OPTION value="option 2">A3-1<OPTION value="option 3">A3-1</select></td>
<td>
<input type="button" value="Copie" onclick="clone(this.parentNode.parentNode, '_1_1_2_1');">
<input type="button" value="New" onclick="cloneEtVide(this.parentNode.parentNode, '_1_1_2_1');">
<input type="button" value="Suppr." onclick="supprLigne(this.parentNode.parentNode);">
</td>
</tr>
<tr id="2">
<td class="tdSpe" NOWRAP> <input type="text" value="input text B1" name="_1_1_2_2_3_1" size="16" maxlength="64"></td>
<td> <input type="text" value="_1_1_2_2_4_1" name="_1_1_2_2_4_1" size="16" maxlength="64"></td>
<td class="tdSpe" NOWRAP> <TEXTAREA WRAP="soft" name="_1_1_2_2_5_1" ROWS="2" COLS="16">textarea B2</TEXTAREA></td>
<td class="tdSpe" NOWRAP> <select name="_1_1_2_2_6_1"><OPTION value="">--<OPTION value="option 1">B3-1<OPTION value="option 2">B3-1<OPTION value="option 3">B3-1</select></td>
<td>
<input type="button" value="Copie" onclick="clone(this.parentNode.parentNode, '_1_1_2_2');">
<input type="button" value="New" onclick="cloneEtVide(this.parentNode.parentNode, '_1_1_2_2');">
<input type="button" value="Suppr." onclick="supprLigne(this.parentNode.parentNode);">
</td>
</tr>
<tr id="3">
<td> <input type="text" value="input text C1" name="_1_1_2_3_3_1" size="16" maxlength="64"></td>
<td> <input type="text" value="_1_1_2_3_4_1" name="_1_1_2_3_4_1" size="16" maxlength="64"></td>
<td> <TEXTAREA WRAP="soft" name="_1_1_2_3_5_1" ROWS="2" COLS="16">textarea C2</TEXTAREA></td>
<td> <select name="_1_1_2_3_6_1"><OPTION value="">--<OPTION value="option 1">C3-1<OPTION value="option 2">C3-1<OPTION value="option 3">C3-1</select></td>
<td>
<input type="button" value="Copie" onclick="clone(this.parentNode.parentNode, '_1_1_2_3');">
<input type="button" value="New" onclick="cloneEtVide(this.parentNode.parentNode, '_1_1_2_3');">
<input type="button" value="Suppr." onclick="supprLigne(this.parentNode.parentNode);">
</td>
</tr>
</table>
</table>
</body>
</html> |
Partager