1
while($row = mysql_fetch_array($result)){
  echo '<tr>';
  echo '  <td><input name="types[]" type="checkbox" value="' . $row['type'] . '" /></td>';
  echo '  <td>' . $row['type'] . '</td>';
  echo '  <td><input size="3" type="text" name="quantities[]" id="TBox-' . $TBCounter . '" /></td>';
  echo '</tr>';
}

it's hard to find on the internet for this solution. how do i store selected checkboxes value into types[] and quantities[]?

i would like to do a POST in php

Tom
  • 3,450
  • 22
  • 31
vinz
  • 350
  • 2
  • 9
  • 19

4 Answers4

1

how do I retrieve the types[] and quantities[]

So you want to know how to determine which of the types[] checkbox values are checked, and store those values in an array?

You'd retrieve all the checkboxes by name, then loop through while checking the checked property

var selected = [];
var allCbs = document.getElementsByName("types[]");
for(var i = 0, max = allCbs.length; i < max; i++)
    if (allCbs[i].checked === true)
        selected.push(allCbs[i].value);
Adam Rackis
  • 82,527
  • 56
  • 270
  • 393
0

By using $_GET or $_POST on the page that you're POSTing to.

Mr. Llama
  • 20,202
  • 2
  • 62
  • 115
  • sorry rephrased my qns. how do i store selected checkboxes value into types[] and quantities[]? – vinz Feb 07 '12 at 20:31
0

HTML Input Forms – Sending in an array in PHP

Peter Kiss
  • 9,309
  • 2
  • 23
  • 38
0

When you click submit button of this form, all checked values will be sended by method that you declared:

something like <form name="name" method="Post" action="file.php"> ... </form>.

Then inside file.php you can get types as array: $_POST['types']. This array will contain checked values

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Tural Ali
  • 22,202
  • 18
  • 80
  • 129