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 8337613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:21:06+00:00 2026-06-09T04:21:06+00:00

I know that may have a few similar questions @stackoverflow, but I didnt found

  • 0

I know that may have a few similar questions @stackoverflow, but I didnt found any solution to my problem yet :s

<?php
while($rowVideo = mysql_fetch_array($ResultQueryVideo))
{
?>
<input type="checkbox" name = "checkbox-1[]" class="checkbox" value ="<?php echo $rowVideo['idVideo'] ?>" /> <?php....some code...

This results a few checkbox’s, the same number as idVideo..thats the point.

Now, before the submit, I need to be sure that at least one checkbox is checked. But i was not sucesseful 😡

function isCountCheck (helperMsg) {
    var chkCnt = 0;
    var Frm = document.forms[0];
    var dLen = Frm.length - 1;
    for (i=0;i<=dLen;i++) {
        if(document.form1.["checkbox-1[]"].checked) chkCnt++;
    }

    if (chkCnt>0) {
        return true;
    } else {
        alert(helperMsg);
        return false;
    }
}

Extra details:
form name = “form1”

Can you guide me a litle ?
Thanks

EDIT:

function isCountCheck(){
    if($("input[type=checkbox]:checked").length > 0)
    {
    return true;
    }
    else
    {
    alert('Invalid');
    return false;
    }
}

But still not working..even that alert is shown..

  • 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-09T04:21:07+00:00Added an answer on June 9, 2026 at 4:21 am

    The main problem is that you’re not using the i index within the loop to reference the individual checkboxes, and you’ve got a . just before the [ which is a syntax error. So change:

    if(document.form1.["checkbox-1[]"].checked) chkCnt++;
    

    To:

    if(document.form1["checkbox-1[]"][i].checked) chkCnt++;
    

    But you can neaten up the function somewhat as follows:

    function isCountCheck(helperMsg) {
        var i, dLen = document.form1["checkbox-1[]"].length;
        // if the length property is undefined there is only one checkbox
        if (typeof dLen === "undefined") {
            if (document.form1["checkbox-1[]"].checked) return true;
        }
        else {
            for (i = 0; i < dLen; i++) {
                if (document.form1["checkbox-1[]"][i].checked) return true;
            }
        }
        alert(helperMsg);
        return false;
    }
    

    Demo: http://jsfiddle.net/nnnnnn/ZjK3w/1/

    Or just loop through all inputs in the form, checking the type (and/or the name) of each one:

    function isCountCheck(helperMsg) {
        var i, len, inputs = document.form1.getElementsByTagName("input");
        for (i = 0, len = inputs.length; i < len; i++) {
            if (inputs[i].type === "checkbox"
                && inputs[i].checked)
                return true;
        }
        alert(helperMsg);
        return false;
    }
    

    Demo: http://jsfiddle.net/nnnnnn/ZjK3w/2/

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

Sidebar

Related Questions

I've looked through similar questions but not found the exact working solution I'm after.
This is similar to a few other threads i have found, but I haven't
I know that may sound silly, but I'm trying to submit a form on
I know that this may be an amateur question but for some reason I
Do you know any tools that may help to implement basic SQLite-based persistence in
I know this question may have appeared few times here and in the internet.
I had looked through the threads and there are few similar questions but I
I know that a kernel may be launched with the triple brackets syntax: kernel<<<NumOfBlocks,
Long version: Those familiar to the standardization nightmare of the RSS-family, may know that
I know that the UI elements (View hierarchy) may only be manipulated from the

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.