Jump to content

Archived

This topic is now archived and is closed to further replies.

digitalgod

checkbox help *solved*

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

Share this post


Link to post
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]

Share this post


Link to post
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. 

Share this post


Link to post
Share on other sites

×

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.