/    Sign up×
Community /Pin to ProfileBookmark

Selecting all checkboxes

i have a javascript function that should select all the checkboxes when a link is clicked. however, it cannot work when there is only 1 checkbox. the following is my code. is there anything that i have done wrong? Thanks.

<head>
<script language=”JavaScript” type=”text/JavaScript”>
<!–
function checkAll(field) {
[INDENT] for (i = 0; i < field.length; i++) {[/INDENT]
[INDENT] [INDENT] field[i].checked = true;[/INDENT][/INDENT]
[INDENT] } [/INDENT]
}
//–>
</script>
</head>

<body>
<form name=”form1″>
Select: <a href=”javascript:checkAll(document.form1.checkbox)”><u>All</u></a>
<%
[INDENT]for (int i = 0; i < 1; i++) { %>[/INDENT]
[INDENT][INDENT]<br><input type=”checkbox” name=”checkbox” value=”checkbox”>[/INDENT][/INDENT]
<% } %>
</form>
</body>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceJul 07.2006 — When there is only one, there is no [B]length[/B] property. You must check for that first.
Copy linkTweet thisAlerts:
@noob06authorJul 07.2006 — thanks.. i got it working...
Copy linkTweet thisAlerts:
@phpnoviceJul 07.2006 — You're welcome.

Cheers.
×

Success!

Help @noob06 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.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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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