I want to get the parameter in my table (HTLML) table every time the user click edit button.
The table contains in each row an edit button like following:
retour.append("<td>");
retour.append("<button id=edit name=edit type=button onClick= editarow()>");
retour.append("<img src=edit.gif />");
retour.append("</button>");
retour.append("</td>");
to get the value of each row where edit is clicked using javascript I do the following:
function editarow(){
var table = document.getElementById("sheet");
var buttons = table.getElementsByTagName("button");
for(var i=0; i<buttons.length; i++) {
if(buttons[i].name=="edit") {
buttons[i].onclick = function()
{
var buttonCell = this.parentNode; //cell
var editThisRow = buttonCell.parentNode; //td
var er=editThisRow.parentNode.attributes[1].value;
alert(er);
}
}
}
}
but I didn’t get the values expected.
Your have an error in your
buttonelement, this:should be
(The “C” should be lower case, and the function call in quotes.)
Let’s assume a row looks like this:
In
editarow, you can do this:This is all made a lot easier if you use jQuery, Prototype, Closure, or other libraries. (For instance, the
findElementfunction above is very crude; its purpose is to skip over text nodes and such.)