/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Delete table rows and update onclick afterwards

I have a table that gets data added to dynamicaly, rows containing data with the last td containing a buttong with a onlclick to delete the row. The button calls a delete function that takes a int as parama representing the row number. now when i delete the row the row numbers must be adjusted, this i do with a function, but it seems it doesnt work. Any ideas why?

[code=php]var tbl = document.getElementById(“filtable”);
var rows = tbl.getElementsByTagName(“TR”);
var rowcount = tbl.getElementsByTagName(“TR”).length;
for(var i=0;i<rowcount;i++){
rows[i].lastChild.onclick = function(){delFilter(i)};
}[/code]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangApr 02.2008 — The button handler doesn't need to know the row number.

You can retrieve the row number using [I]obj.rowIndex[/I], in your case that would probably be [I]this.parentNode.parentNode.rowIndex[/I]
Copy linkTweet thisAlerts:
@kloon_zaauthorApr 02.2008 — Great thanks, works perfectly.
×

Success!

Help @kloon_za 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,
)...