/    Sign up×
Community /Pin to ProfileBookmark

Check/Uncheck problem with checkbox

Hi,

Good day to all.

I experienced an issue with the check/uncheck module.

The java code below works fine if there are more than one “field”.

If there’s only one field it will show some error as “0.checked is null or not an object”

Can anyone help?

Regards,
Jack

<!–
var checkflag = “false”;

function check(field) {
if (field[0].checked) {
for (i = 0; i < field.length; i++)
{field[i].checked = false;}
checkflag = “true”;
return “Uncheck All”;
}
else {
for (i = 0; i < field.length; i++)
{field[i].checked = true; }
checkflag = “false”;
return “Check All”;
}
}

//–>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Willy_DuittMar 09.2005 — A for loop assumes that there are more than one...

Try using a while loop or write another conditional to account for if the length of the collection is one or less than one...

.....Willy

Oh... You could try counting back towards zero from the collection length, rather than up from zero towards the collection length...
×

Success!

Help @jacknbey 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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