Jump to content

Recommended Posts

hey guys,

I have a form that has multiple checkboxes, I want to be able to retrieve the value of the ones that are checked but for some reason this isn't working and I can't seem to find out why

[code=php:0]
$aBottles = array();
$aQty = array();
//$_SESSION['reserve_qBottlesCount'] returns 1 like it's supposed to
for ($i=1; $i <= $_SESSION['reserve_qBottlesCount']; $i++) {
  array_push($aBottles,$_POST['chk'.$i]);
  array_push($aQty,$_POST['sel'.$i]);
}
[/code]

and this is part of the form

[code]
<tr>
<td> <input type="checkbox" id="chk'.$c.'"  value="'.$bottles_row2['name'].'" style="height:17px; font-family:tahoma; font-size:10px; color:#9A400C "/> </td>
<td> <strong>'.$bottles_row2['name'].'</strong> </td>
<td> Price: $<span id="txtPrice'.$c.'">'.$bottles_row['price'].'</span> </td>
<td> Qty: <select id="sel'.$c.'"  style="width:40px; height:17px; font-family:tahoma; font-size:10px; color:#9A400C ">
<option value="val0">0</option>
<option value="val1">1</option>
<option value="val2">2</option>
<option value="val3">3</option>
</select> </td>
</tr>
[/code]

everything is displayed the way it's supposed to and if I look at the source of the page I can see that the id of the checkbox is chk1 like it's supposed to be..

any clues why it's not working?

*edit*

when I echo $_POST['chk'.$i] it doesn't output anything, even though there is a value and the checkbox was checked
Link to comment
https://forums.phpfreaks.com/topic/24258-checkbox-help-solved/
Share on other sites

try something like this
[code]
<?php
if (isset ($submit)) {
    foreach ($_POST['cb'] as $id => $val) {
        echo "$id - $val <br />";
    }
}
?>
<form method='post'>
<input type="checkbox" name="cb[id1]" value="1">  1 <br/>
<input type="checkbox" name="cb[id2]" value="2">  2 <br/>
<input type="checkbox" name="cb[id3]" value="3">  3 <br/>
<input type="submit" name="submit" value="Submit">
</form>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/24258-checkbox-help-solved/#findComment-110270
Share on other sites

from what i understand, 'id' can be used instead of 'name' for client side stuff, like destinations for links, referencing an element, applying a particular style to the element with a style sheet, but it will not be posted to the server; only 'name' will. 
Link to comment
https://forums.phpfreaks.com/topic/24258-checkbox-help-solved/#findComment-110556
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.