Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Select all or any checkboxes and Get the selected checkboxes

Posted on 2003-12-04
4
Medium Priority
?
1,444 Views
Last Modified: 2008-03-17
Hello,

I have created a HTML form which has 4 checkboxes and one checkboxes, if checked, checks all the checkboxes, i mean it's a select all checkbox and i have written a JavaScript code for selecting all checkboxes.

But i am not able to get the checkboxes those are checked though a PHP script as the name of all the checkboxes had to keep same as invoke a JavaScipt function to select all checkboxes it user needs.

I do i get which checkboxes are checked. My checkbox html code is:
<input type="checkbox" name="list" value="Check All" onClick="this.value=check(this.form.list);">Select All
<input type="checkbox" name="list" value="1">Elastic Modulus
<input type="checkbox" name="list" value="2">Poisson's Ratio
<input type="checkbox" name="list" value="3">Coefficient of Thermal Expansion
<input type="checkbox" name="list" value="4">Density
0
Comment
Question by:maratmu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Expert Comment

by:aolXFT
ID: 9875896
You need to send them as an array.

<input type="checkbox" name="list" value="1">Elastic Modulus

Would change to

<input type="checkbox" name="list[]" value="1">Elastic Modulus

Then for elastic Modulus you would check for the value 1 in the array $_POST['list'](if using post method), using in_array.

if(in_array(1, $_POST['list'])){
  $elastic_modulus = true;
}

I'm not sure how you'd tackle the Javascript though.
0
 
LVL 7

Expert Comment

by:petoskey-001
ID: 9877022
Another possible problem is using the same name for multiple checkboxes.  While this is valid HTML, php 4.3.3 for windows shows only the value of the last checked checkbox when using the POST method in the form.  If you use the GET method on your form you will still only get on result in your _Request["list"] variable, but you can pull the other responses from _SERVER["QUERY_STRING"].

The best solution would be to change the name of your checkboxes so each one is unique.  Then you don't have to deal with it.

Here is a link for implementing something similar that might work for you.

http://www.skyzyx.com/scripts/togglecheck.php

0
 
LVL 6

Accepted Solution

by:
aolXFT earned 240 total points
ID: 9877166
> The best solution would be to change the name of your checkboxes so each one is unique.  Then you don't have to deal with it.

That won't work for him, because he has a JS Select All, for which he needs to have all the names the same.

Having that said, if he changed the names to have unique names, and had some other attribute the same, such as ID that could implement the Select All function that would be a nice solution too.

Pulling responses from $_SERVER['QUERY_STRING'] is messy, and a very ugly hack in PHP. It also assumes use of the GET method.
0
 

Author Comment

by:maratmu
ID: 9878522
The Different ID funda and keeping name same worked , thank you
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question