/    Sign up×
Community /Pin to ProfileBookmark

check checkbox onChange of another field

I have a form that is basically a table from my database. I have checkboxes on the left and only those checked get updated on submit. I’m trying to make an function that is called with an onChange event that will check the box if any of the fields in that row are altered. The id of the checkbox is checkeds[i] where “i” is the row number. The function is firing, but the box isn’t getting checked. Any ideas?

[CODE]function checkBox(row)
{
var checkedId = ‘checkeds[‘ + row + ‘]’;
document.getElementById(checkId).checked=true;
}[/CODE]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@WolfShadeMar 02.2011 — function checkBox(row)

{

var [color=red]checkedId[/color] = 'checkeds[' + row + ']';

document.getElementById([color=red]checkId[/color]).checked=true;

}

As of right now, this is the only discrepancy that I can see.

^_^
Copy linkTweet thisAlerts:
@marcdd2authorMar 02.2011 — Thanks, but that was just an accidental cut.

The field code for the first row is:

[CODE]<input type="hidden" name="checkeds[0]" id="checkeds[0]" value="0">
<input type="checkbox" name="checkeds[0]" id="checkeds[0]" value="1" />[/CODE]


Does the hidden field effect it? I guess there is no reason to give that the same id.
Copy linkTweet thisAlerts:
@marcdd2authorMar 02.2011 — That was the issue. Thanks for the help.
Copy linkTweet thisAlerts:
@cluefulMar 03.2011 — 
[CODE]<input type="hidden" name="checkeds[0]" id="checkeds[0]" value="0">
<input type="checkbox" name="checkeds[0]" id="checkeds[0]" value="1" />[/CODE]
[/QUOTE]
Names can be duplicated, but all IDs in a document must be unique.
×

Success!

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