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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:40:19+00:00 2026-05-23T06:40:19+00:00

I have a question regarding checkboxes. <form method=post> I speak the following languages: <input

  • 0

I have a question regarding checkboxes.

<form method="post">
I speak the following languages:
<input type="checkbox" name="lang[]" value="en">English<br />
<input type="checkbox" name="lang[]" value="fr">Français<br />
<input type="checkbox" name="lang[]" value="es">Español<br />
</form>

Is it necessary to name the checkboxes lang[] (using an array) or can I give each checkbox a seperate name, like:

<form method="post">
I speak the following languages:
<input type="checkbox" name="lang_en" value="en">English<br />
<input type="checkbox" name="lang_fr" value="fr">Français<br />
<input type="checkbox" name="lang_es" value="es">Español<br />
</form>

Question 1 I believe both works, if so when do you decide which to use?

Question 2 I am using the second method listed above so I can use PHP to detect which of the checkbox is selection by using a code similar to if(isset($_POST['lang_en'])). If I were to use the first method, is there a quick way to check if a particular checkbox is selected? At the moment the untested solution I can think of involves doing a if(in_array('lang_en', $_POST['lang'])) to check if it exist in $_POST.

Question 3 The main question is this: I am using the second method so I can easily check if a checkbox is selected in PHP. Now I want to add a text link which when clicked will select all the checkboxes. My Javascript is not too good, so I am using a script from http://www.shiningstar.net/articles/articles/javascript/checkboxes.asp but the example script uses an array for the checkbox’s names while my PHP code cannot check if the checkboxes are selected with arrays are used for the checkbox’s names. How can the javascript code be modified to work without arrays?

Hope I can get this annoying question figured out! Thanks!

EDIT

Javascript:

<!-- Begin
function checkAll(field)
{
for (i = 0; i < field.length; i++)
    field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
field[i].checked = false ;
}
//  End -->
</script>

HTML:

<form action="http://localhost/website/places/search" method="post" accept-charset="utf-8" name="subcategory">

<ul>
  <li><input type="checkbox" name="cuisine_American" value="American" /> American</li>
  <li><input type="checkbox" name="cuisine_Chinese" value="Chinese" onClick="checkAll(document.subcategory.cuisine)" /> Chinese</li>
  <li><input type="checkbox" name="cuisine_Indian" value="Indian" onClick="checkAll(document.subcategory.cuisine)" /> Indian</li>
  <li><input type="checkbox" name="cuisine_Japanese" value="Japanese" onClick="checkAll(document.subcategory.cuisine)" /> Japanese</li>
  <li><input type="checkbox" name="cuisine_Korean" value="Korean" onClick="checkAll(document.subcategory.cuisine)" /> Korean</li>
  <li><input type="checkbox" name="cuisine_Mexican" value="Mexican" onClick="checkAll(document.subcategory.cuisine)" /> Mexican</li>
  <li><input type="checkbox" name="cuisine_Middle Eastern" value="Middle Eastern" onClick="checkAll(document.subcategory.cuisine)" /> Middle Eastern</li>
  <li><input type="checkbox" name="cuisine_Pakistani" value="Pakistani" onClick="checkAll(document.subcategory.cuisine)" /> Pakistani</li>
  <li><input type="checkbox" name="cuisine_Italian" value="Italian" onClick="checkAll(document.subcategory.cuisine)" /> Italian</li>
</ul>

</form>
  • 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-23T06:40:20+00:00Added an answer on May 23, 2026 at 6:40 am

    Answers:

    1. Either works…depends on whether you want explicit names or an array
    2. You can also use array_key_exists()
    3. Can you post the javascript code you are using into your question? I’ll take a further look…

    UPDATE:

    Here is a jQuery solution for implementing your onclick handlers:

    function checkAll(field){
        $(':checkbox[name^="cuisine_"]').each(function(index){
            this.checked=true;
        });
    }
    
    function uncheckAll(field){
        $(':checkbox[name^="cuisine_"]').each(function(index){
            this.checked=false;
        });
    }
    

    Note that you really don’t need to pass in field, unless you want to generalize this and pass in the string for the startswith pattern (e.g. cuisine_).

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

Sidebar

Related Questions

I'm writing a small webapp in Grails and I have the following question regarding
Following on from my recent question regarding parsing XML files in Java I have
Hi I have a question regarding a method to prevent second voting in a
I have a question regarding the two additional columns (timeCreated, timeLastUpdated) for each record
I have a question regarding an update function I created... CREATE OR REPLACE FUNCTION
I have a question regarding handling errors in a J2EE application. Our current application
I have a question about best practices regarding how one should approach storing complex
I have a simple question and wish to hear others' experiences regarding which is
I have a question regarding the ASP.NET 3.5 Treeview and Treenodes. I'd like to
I have a question regarding using intptr_t vs. long int . I've observed that

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.