digitalgod Posted October 17, 2006 Share Posted October 17, 2006 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 tofor ($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 Quote Link to comment https://forums.phpfreaks.com/topic/24258-checkbox-help-solved/ Share on other sites More sharing options...
Barand Posted October 17, 2006 Share Posted October 17, 2006 Form elements need names Quote Link to comment https://forums.phpfreaks.com/topic/24258-checkbox-help-solved/#findComment-110251 Share on other sites More sharing options...
digitalgod Posted October 17, 2006 Author Share Posted October 17, 2006 so the id alone isnt good enough? Quote Link to comment https://forums.phpfreaks.com/topic/24258-checkbox-help-solved/#findComment-110254 Share on other sites More sharing options...
Barand Posted October 17, 2006 Share Posted October 17, 2006 try something like this[code]<?phpif (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] Quote Link to comment https://forums.phpfreaks.com/topic/24258-checkbox-help-solved/#findComment-110270 Share on other sites More sharing options...
digitalgod Posted October 18, 2006 Author Share Posted October 18, 2006 no it's ok I just added the name field but I was just wondering how come the id alone isnt enough Quote Link to comment https://forums.phpfreaks.com/topic/24258-checkbox-help-solved/#findComment-110392 Share on other sites More sharing options...
.josh Posted October 18, 2006 Share Posted October 18, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/24258-checkbox-help-solved/#findComment-110556 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.