/    Sign up×
Community /Pin to ProfileBookmark

Making Checkbox as selected

Hi,

I’m having the following javascript code,after all the checkboxes are unslected,I’ll display the alert to user saying that “Atleast one must be selected”,but the checkbox is becoimng unselected after throwing Alert,how to make check box to remain selected after throwing this alert.

var checkSelected = false;
for (i = 0; i < planForm.locationOptions.length; i++) {
if (planForm.locationOptions[i].checked) {
checkSelected = true
document.planForm.action=’refreshPlanView.do’;document.planForm.submit();
document.getElementById(“refreshing”).style.display=”block”;
}
}
if (!checkSelected) {
alert(“At least ONE Location must be selected!”);
return false;
}
return true;
}

Please advise..

Thanks,
Kumar

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorSep 05.2007 — the validation function should be placed in the [B]form [/B]element ([I]onsubmit[/I]), not in the [B]checkbox[/B] ([I]onclick[/I]). I suspect that you call the function onclick or, in this case, the [B]return false[/B] statement will prevent the HTML action (the check action, your case). [B]return false[/B] should prevent the HTML submit action, not the HTML click/check action...
×

Success!

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