/    Sign up×
Community /Pin to ProfileBookmark

Control confrim delete

Hello,

The alert() musn’t display, if any checkbox(s) isn’t selected.
How can I do this?

[code=php]
<script language=”javascript”>
function confirmDel() {
var agree=confirm(“Are you sure you want to delete rows?!”);
if (agree) {
return true ; }
else {
return false ;}
}
</script>

<input type=”checkbox” name=”name[]” value=”<?=$id?>”>
<input type=”checkbox” name=”name[]” value=”<?=$id?>”>
<input type=”checkbox” name=”name[]” value=”<?=$id?>”>
<input type=”checkbox” name=”name[]” value=”<?=$id?>”>
<input type=”checkbox” name=”name[]” value=”<?=$id?>”>

<input type=”submit” onclick=”return confirmDel();” />
[/code]

Thanks in advance

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@ZABIMay 03.2013 — [CODE]
<script language="javascript">
function confirmDel() {
var inputElems = document.getElementsByTagName('input'), count = 0;
for (var i=0; i<inputElems.length; i++) {
if (inputElems[i].type === 'checkbox' && inputElems[i].checked === true) {
count++;
}
}

if (count<1){alert('select atleast one item');return false;}
var agree=confirm("Are you sure you want to delete rows?!");
if (agree) {
return true ; }
else {
return false ;}
}
</script>

<input type="checkbox" name="name[]" value="<?=$id?>">
<input type="checkbox" name="name[]" value="<?=$id?>">
<input type="checkbox" name="name[]" value="<?=$id?>">
<input type="checkbox" name="name[]" value="<?=$id?>">
<input type="checkbox" name="name[]" value="<?=$id?>">

<input type="submit" onclick="return confirmDel();" />
[/CODE]
Copy linkTweet thisAlerts:
@AdemauthorMay 03.2013 — Excellent, thank you so very much
×

Success!

Help @Adem 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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