0

Help me:

<input type="checkbox" name="cd[]" checked="checked" value="1">
JAVA<br>
<input type="checkbox" name="cd[]" value="0">
PERL<br>
<input type="checkbox" name="cd[]" value="0">
PYTHON<br>
<input type="checkbox" name="cd[]" value="0">
C#<br>
<input type="checkbox" name="cd[]" checked="checked" value="1">

i want to get all value(check and uncheck). But my array show array(1,1). i need array(1,0,0,0,1). And when i checkbox is checked(change value=1). checkbox isn't checked(change value=0).

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by divyakrishnan
0

You could use many deferent approaches to that (array marks in a field name is just a quick dirty fix …) . If you fill these options from PHP then just give names relative to the data that generating them. For example cd_0 is Java … so you will know if you get cd_0 that java is checked , and after that what weren’t checked…

0

Try this code

<body>
<?php
if(isset($_POST['s']))
{
  
 $a=array();
 for($i=0;$i<3;$i++)
 {
 $c='c'.$i;
 if(isset($_POST[$c]))
 {
 echo "R";
 $a[$i]=1;
 }
 else
 {
  $a[$i]=0;

 
 }
 
 }
  
  print_r($a);
  
}
 
 
 
$ck="c";
$i=1;
$name=$ck;
?>
<form id="form1" name="form1" method="post" action="chk_bx.php">
  <input name="<?php echo $name.'0'; ?>" type="checkbox" id="c" value="checkbox" /> 
  ASP
  <input name="<?php echo $name.'1'; ?>" type="checkbox" id="c" value="checkbox" /> 
  JSP
  <input name="<?php echo $name.'2'; ?>" type="checkbox" id="c" value="checkbox" /> 
  PHP
  <input name="s" type="submit" />
</form>
</body>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.