Jump to content


Photo

checkbox help *solved*


  • Please log in to reply
5 replies to this topic

#1 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 17 October 2006 - 07:51 PM

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

$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]);
}

and this is part of the form

<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>

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

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 17 October 2006 - 08:16 PM

Form elements need names
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 17 October 2006 - 08:20 PM

so the id alone isnt good enough?

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 17 October 2006 - 09:09 PM

try something like this
<?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>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 18 October 2006 - 12:37 AM

no it's ok I just added the name field but I was just wondering how come the id alone isnt enough

#6 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 18 October 2006 - 09:14 AM

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. 
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users