/    Sign up×
Community /Pin to ProfileBookmark

html edit button in javascript

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>[/code]

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);[/CODE]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @LilithD spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...