I’ve 3 text fields and I have 3 checkboxes attached with it. I want to store the values of only those textboxes in one varible whose respective checkboxes is checked. with the help of following codes I can access the values of all the textboxes but for that I’ve to check all the checkboxes, where as I want to be selective with it. If only 2 checkboxes are checked then I want to have only 2 respective textboxes values stored in a varible.
HTML:
<html>
<head></head>
<body>
<form action="access.php" method="POST">
<tr>
<td>Address:</td><td> <input type="text" name="address" value="<?php echo "$address"?>" disabled="disabled" id="field1" /></td>
<td><input id="CheckBox[]" type="checkbox" onClick="enableText1(this.checked, 'field1');" name="CheckBox1" /></td>
</tr>
<tr>
<td>Source: </td><td><input type="text" name="source" value="<?php echo "$source"?>" disabled="disabled" id="field2" /></td>
<td><input id="CheckBox[]" type="checkbox" onClick="enableText2(this.checked, 'field2');" name="CheckBox2" /></td>
</tr>
<tr>
<td>Mobile:</td><td> <input type="text" name="mobile" value="<?php echo "$mobile"?>" disabled="disabled" id="field3" /></td>
<td><input id="CheckBox[]" type="checkbox" onClick="enableText3(this.checked, 'field3');" name="CheckBox3" /></td>></td>
</tr>
<tr style="border:#FFF";>
<td><input type="Submit" name="submit" value="Update"></td>
</tr>
</form>
</table>
</body>
</html>
PHP:
<?php
if(isset($_POST['CheckBox1']))
{
if(isset($_POST['CheckBox2']))
{
if(isset($_POST['CheckBox3']))
{
$b=array($address,$source,$mobile);
$a=implode('', $b);
print $a;
}
}
}
?>
With the help of the above codes if I check all the checkboxes then I am able to print all the 3 textbox’s values but if I do not check all the checkboxes then it does not show the value of the respective textboxes. I do not want to change the name of the textboxes name as m going to accept these values to insert into the database. can anyone please sort out this problem? cheers..
access.php
use it.