/    Sign up×
Community /Pin to ProfileBookmark

unobtrusively ignoring click on CHECKBOX

i’ve created a couple functions that allow a user to select a checkbox by clicking anywhere in the same table row. It works by parsing an array of <td>s in the row, looking for the checkbox and switching it’s state. Small problem. If the user clicks on the checkbox itself, it selects it and immediately unselects it ? Any suggestions?

[code]if(rows=document.getElementsByTagName(‘TR’)) {
for(x=0; x<rows.length; x++) {
rows[x].onclick=function() {toggleSelect(this)}
}
}

function toggleSelect(row) {
cells=row.getElementsByTagName(‘TD’);
for(y=0; y<cells.length; y++) {
if(checkbox=cells[y].getElementsByTagName(‘INPUT’)[0]) {
if(!checkbox.checked) {
checkbox.checked=true;
} else {
checkbox.checked=false;
}
}
}
}[/code]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @bcamp1973 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.2,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...