Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7495289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:01:09+00:00 2026-05-29T18:01:09+00:00

I need help on making a delete confirmation that need a minimum of 1

  • 0

I need help on making a delete confirmation that need a minimum of 1 record to be deleted.
I’m still confused on making it. I think there’s something wrong in my javascript code. Any help would much be appreciated. Thanks

here’s the php code:

enter code here

<script src="javascript.js" type="text/javascript"></script>
<?php
echo"<form method=POST action='action.php?act=delete'>
     <input type=checkbox name='checkbox[]' value='1'>1
     <input type=checkbox name='checkbox[]' value='2'>2
     <input type=checkbox name='checkbox[]' value='3'>3
     <input type=submit value=Delete onClick='return del_confirm();'></form>";
?>

here’s the javascript code:

enter code here

function del_confirm()
{
var msg=confirm('Are you sure?');
var c=document.getElementsByName('checkbox[]');
if(msg)
{
    for(i=0;i<c.length;i++)
    {
    if(c[i].checked)
    {
        return true;
    }
    else
    {
        alert("Select minimum of 1 record to be deleted!");
        return false;
    }
    }
}
else
{return false;}
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T18:01:11+00:00Added an answer on May 29, 2026 at 6:01 pm

    Your logic is a bit off:

    function del_confirm() {
        var msg = confirm('Are you sure?');
        var c = document.getElementsByName('checkbox[]');
        if(msg) {
            for(i = 0; i < c.length; i++) {
                if(c[i].checked) {
                    return true;
                }
            }
            // This has to be outside the for loop,
            // that way it only gets here if every box is not checked
            alert("Select minimum of 1 record to be deleted!");
            return false;
        } else {
            return false;
        }
    }​
    

    You had the alert inside the for loop so the first unchecked box returned false for the function.

    Example Fiddle: http://jsfiddle.net/FfkvW/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help making an algorithm to detect that all the conditions for HAVE_ENOUGH_DATA
I need some help making a linq query that will select a list of
I need help making AOP work. What am I missing here? <?xml version=1.0 encoding=UTF-8?>
I need help making this loop to move a label move smoothly across the
This is for a tic tac toe game. I need help making a check
I need help making this code work better. Currently, what happens is when it
I need help, badly. What I am making right now is a date picker.
I need help making a search query for comments (it's for a WordPress site).
I have little knowledge of java scripting, and need help making my application work.
I need some help making this program for class. We are working with g++

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.