/    Sign up×
Community /Pin to ProfileBookmark

check box validation

Hi,
As a beginner in Java script, I try to validate check box on the form, so users will be able to delete or add checked record when they click on delete or add buttons.So far what I have is:
function Add_record(iID) {

if (confirmActAdd(iID) == true) {
document.location.href=”taforstu_changes.asp?strAdd=1&strOperation=add&ID=” +escape(iID);
}
else {
return false;
}

}

function Delete_record(iID) {
if (confirmActDel(iID) == true) {
document.location.href=”taforstu_changes.asp?strDelete=1&strOperation=delete&ID=” +escape(iID);
}
else {
return false;
}

}

function confirmActAdd (accomID){

if (confirm(“Are you sure you want to Add Selected Accommodation(s) ” + “?”) == 1) {
alert(“Click OK to proceed with Add.”);
return true;
}
else {
alert(“Skipping Addition of Accommodation.”);
return false;
}
}

function confirmActDel (iID){
if (confirm(“Are you sure you want to Delete Selected Accommodation(s) ” + “?”) == 1) {
alert(“Click OK to proceed with Delete.”);
return true;
}
else {
alert(“Skipping Deletion of Accommodation.”);
return false;
}
}

I now want to validate if any check boxes were selected and put a prompt to make selection. In order to do it I probably should go throught a loop..???

Any help would be appreciated!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@ExuroAug 13.2004 — I think this should work for you:
[code=php]function checkBoxes() {
var inputs = document.getElementsByTagName("input");
var checked = false;
for (var i=0;i<inputs.length&&!checked;i++) {
checked = checked || (inputs[i].type == "checkbox" && inputs[i].checked);
}
if (!checked) {
alert("You have not checked any checkboxes.nPlease make at least one selection.");
}
}[/code]
×

Success!

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