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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:58:47+00:00 2026-05-15T18:58:47+00:00

i have a form with checkboxes like this: <input type=checkbox name=type[] value=1 />Fast Food<br>

  • 0

i have a form with checkboxes like this:

    <input type="checkbox" name="type[]" value="1" />Fast Food<br>
    <input type="checkbox" name="type[]" value="2" />Table Service<br>
    <input type="checkbox" name="type[]" value="3" />Cafeteria<br>

when i use the brackets in the name (type[]), my php works:

    $type=$_POST['type'];

    echo "types are:";
for ( $counter = 0; $counter < sizeof($type); $counter += 1) {
    echo "<br>".$type[$counter];
}

but my javascript doesn’t work:

    var f = document.addform;
    for (var i=0;i<f.type.length;i++){
        if(f.type[i].checked==true){
            break;
        }
        if(i==(f.type.length-1)){
            alert("No categories entered!");
            valid=false;
        }
    }

however, if i take away the brackets:

<input type="checkbox" name="type" value="1" />Fast Food<br>

then the PHP doesn’t work but the javascript does.

what’s going on here? what should i use?

thanks.

  • 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-15T18:58:48+00:00Added an answer on May 15, 2026 at 6:58 pm

    PHP has an unusual system for handling multiple form controls with the same name, it expects the names to include [] but it doesn’t use them in the variable name.

    JavaScript doesn’t have that issue. The property will still have the brackets.

    Of course, square brackets have special meaning in JS, so you can’t use dot notation to access the property.

    f['type[]'][i].checked
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form like this: <form name=mine> <input type=text name=one> <input type=text name=two>
I have a bunch of rows in a form like this <tr> <td nowrap><input
$i=0; while (db_data) { $i++; echo '<input type=checkbox name=v['.$i.'] value='.$url.''; if ($v[$i]) { echo
I have following HTML with two elements having the same name <input type=hidden name=
I have a form with checkboxes and then text to the right of the
I have a form that contains a bunch of checkboxes. Before submitting the form,
I have a form with thousands of checkboxes, and when one is checked, I
It's quite common to have a form with a checkbox stating Use foo immediately
I have a checkbox list control on my asp.net web form that I am
I am implementing an HTML form with some checkbox input elements, and I want

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.