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

  • SEARCH
  • Home
  • 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 8835203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:12:24+00:00 2026-06-14T09:12:24+00:00

Language: Javascript I really hate to ask such a seemingly simple question, but simple

  • 0

Language: Javascript

I really hate to ask such a seemingly simple question, but simple as it seems, I can’t get this to work.

I am trying to do this entirely with pure Javascript alone (no library support).

I have a form with checkboxes…
All checkboxes are named files[] because I use the results in an array:

<input type='checkbox' name='files[]' id='1' value='1' /> file 1<br>
<input type='checkbox' name='files[]' id='2' value='2' /> file 2<br>
<input type='checkbox' name='files[]' id='3' value='3' /> file 3<br>

What I’m trying to do is, when the user submits the form:

  • IF no checkbox is checked >> return ALERT!
  • ELSE submit the form

Here’s my form:

<form name="deleteFiles" action="" method="post" onsubmit="return confirm_update();">

    <input type='checkbox' name='files[]' id='1' value='1' /> file 1<br>
    <input type='checkbox' name='files[]' id='2' value='2' /> file 2<br>
    <input type='checkbox' name='files[]' id='3' value='3' /> file 3<br>
    <input type="submit" value="Submit" name="submit">

</form>​

And here’s my Javascript code:

function confirm_update() {
    var aCheckbox = document.deleteFiles.getElementsByTagName('input');

    if (aCheckbox.checked){
    return confirm("Are you sure you want to proceed deleting the selected files?");

    } else {
        alert("You do not have any selected files to delete.");
        return false;
    }
}​

In action: http://jsfiddle.net/DVqwB/3/

Apparently, it is not working, I know I should use getElementsById but since they each have unique IDs I can’t use that. And I also know that there are lots of solutions on this site, but if you look – they actually use jQuery…

Any help & guidance would be greatly appreciated! Thank you so much.

  • 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-06-14T09:12:25+00:00Added an answer on June 14, 2026 at 9:12 am

    Correct way to iterate the collection will be: (full example)

    function confirm_update() {
        var arrCheckboxes = document.deleteFiles.elements["files[]"];
        var checkCount = 0;
        for (var i = 0; i < arrCheckboxes.length; i++) {
            checkCount += (arrCheckboxes[i].checked) ? 1 : 0;
        }
    
        if (checkCount > 0){
            return confirm("Are you sure you want to proceed deleting the selected   files?");
        } else {
            alert("You do not have any selected files to delete.");
            return false;
        }
    }
    body {
        margin: 30px;
    }
    <form name="deleteFiles" action="" method="post" onsubmit="return confirm_update();">
        
        <input type='checkbox' name='files[]' id='1' value='1' /> file 1<br />
        <input type='checkbox' name='files[]' id='2' value='2' /> file 2<br />
        <input type='checkbox' name='files[]' id='3' value='3' /> file 3<br />
        <input type="submit" value="Submit" name="submit" />
        
    </form>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(This question is not really restricted to the language so please feel free to
Assuming a javascript-like language, how can we implement a system such as: a =
In any sane programming language, from C to Javascript, an expression such as a
I'm new into JavaScript and I really like jQuery and hate when it comes
I'm making my own javascript-based programming language (yeah, it is crazy, but it's for
I'm getting into Haxe. I do really love the agnostic core language, but as
I really can't find good examples for implementing own scripting language using javax.script ...
I've always been dabbling in javascript, but never really got hugely into writing a
This is super simple task to do in Java but the asynchronous nature of
[Disclosure: This question is slightly related to my previous question .] As you can

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.