1 pièce(s) jointe(s)
Creation tables apres click sur un bouton
Bonjour a tous,
Excusez moi d'avance si je dis une connerie, mais c'est le premier code Javascript que j'ecris.
J'ai une table donc je cree l'entete en html mais voila, je voudrais que quand l'utilisateur clique sur un le bouton Add Functionality, deux nouvelles lignes sont ajoutees a la table
j'ai ecrit le code suivant:
Code:
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
| <?php
require_once ('../mysqli_connect.php');
?>
<script>
function start() {
// get the reference for the body
var body = document.getElementsByTagName("body")[0];
// creates a <table> element and a <tbody> element
//var tbl = document.createElement("table");
var tbl = document.getElementById("table");
var tblBody = document.createElement("tbody");
// creating all cells
for (var j = 0; j < 2; j++) {
// creates a table row
var row = document.createElement("tr");
for (var i = 0; i < 4; i++) {
// Create a <td> element and a text node, make the text
// node the contents of the <td>, and put the <td> at
// the end of the table row
var cell = document.createElement("td");
eAnchor = document.createElement("a");
eAnchor.setAttribute("href","delete.php");
eAnchor.appendChild(document.createTextNode("[Delete]"));
cell.appendChild(eAnchor);
row.appendChild(cell);
}
// add the row to the end of the table body
tblBody.appendChild(row);
}
// put the <tbody> in the <table>
tbl.appendChild(tblBody);
// appends <table> into <body>
body.appendChild(tbl);
// sets the border attribute of tbl to 2;
tbl.setAttribute("border", "2");
}
</script>
<form>
<table id="table">
<tr><td colspan="2">
<table align="center" border = "2" cellspacing ="0" cellpadding="3">
<tr><td><b>Functionality Name:</b></td> <td><b>Description:</b></td> <td><b>Status:</b></td> <td><input type="submit" value="Add Functionality" onclick='start();'></td></tr>
</table>
</td></tr>
</table>
</form> |
le resultat est en fichier attache (vori resultat.jpg)
Ce resultat ne correspond pas a ce que je veux. Je voudrais que les deux lignes supplementaires qui s'ajoutent en fin de table a chaque fois que l'utilisateur clique sur Add Functionality, soient alignees avec l'entete de la table.
Pouvez vous m'aider a le faire?
Merci
Billy