My html page has a table which is populated by a javascript array. In that table, I have an edit and delete button. My problem is that I don’t know how to get the edit button to work. I am trying to figure out how to pass the row number from the html to the javascript so that I may edit it, but I can’t seem to figure out how to do it and I haven’t found anything on the site that addresses my problem.
[code=html]
<table id=”tableHead”>
<thead>
<tr>
<th>Last Name</th>
<th>First Name</th>
<th>Telephone</th>
<th>Email</th>
<th></th>
</tr>
<tr>
<th>Doe</th>
<th>Jane</th>
<th>423-555-1234</th>
<th>[email protected]</th>
<th></th>
</tr>
</thead>
<tbody id=”body”>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</tbody>
<button type=”button” onclick=”addContact()”>Add Contact</button>
This is what I have so far…
[CODE]function editContact(r) {
var i = r.parentNode.parentNode.rowIndex;
var table = document.getElementById(“body”);
//document.getElementById(“body”).editRow(i);
if(table.rows[i].cells[3].childNodes[0].value ==”Edit”){
var name = table.rows[i].cells[0].innerHTML;
var lastName = table.rows[i].cells[1].innerHTML;
var firstName = table.rows[i].cells[2].innerHTML;
var phone = table.rows[i].cells[0];
var email = table.rows[i].cells[1];
lastName.innerHTML = “”;
var last_name = document.createElement(“input”);
lastName.id = “last_name”;
lastName.appendChild(last_name);
firstName.innerHTML = “”;
var first_name = document.createElement(“input”);
firstName.id = “first_name”;
firstName.appendChild(first_name);
phone.innerHTML = “”;
var tele = document.createElement(“input”);
phone.id = “tele”;
phone.appendChild(tele);
email.innerHTML = “”;
var e_mail = document.createElement(“input”);
email.id = “e_mail”;
email.appendChild(e_mail);