Click to See Complete Forum and Search --> : Problems with dynamically created checkbox


andyl
10-16-2003, 05:30 PM
Hi there,
Hope someone can help with this

The problem I have concerns a dynamically created table/form which pulls in results from a user search of a mysql database. This works fine and pulls in results (title/author/isbn/price) and dynamically creates the table dependent upon how many results are found. For each result there is a dynamically created checkbox, which is bound to a unique field from the database(in this case isbn).

My problem then is: the dynamically created checkbox submits an isbn value to the next page - an order form. However I need that a user can select a number of checkboxes from the table. At the moment, each selection overwrites the other. It may be vary obvious - but I need to work out some way of storing the checkbox info in an array that gets submitted to my order form page.

at the moment the code for my checkbox within the html form is:


<input name="isbn_input" type="checkbox" id="isbn_input" value="<?php echo $row_Rs_panozzo_search['isbn']; ?>" />
</font></td>

This works passing one value through to my order form, but I need to set it up so it passes multiple values.

Hope I've explained this clearly enough

Thanks!
Andy

TheIceman5
10-17-2003, 10:01 PM
dunno, need to see some more code.
if u posted this in the corret forum it would be most probably answered by now, not many people visit this section of the forum.

tshafer
10-18-2003, 10:12 PM
both the name and id for the checkbox need to be "isbn_input[]". This will make any results populate an array.

---tom

bodzan
10-23-2003, 08:35 PM
As the previous member said, but one more thing:

You might want the script on the form processing page to check all of your checkboxes in order to see whether they are checked and then take an apropriate action...

Say you have dinamically formed an form with sayx checkboxes...

I don't know how you dinamically write them in your page but lets say something like (this is PHP coding but the idea is there):

$i=0;
while($i<$total){
echo "<input type=\"checkbox\" name=\"check_bow[".$i."]\" value=\"whatever\">";
$i++;
}

This way you would have printed out $total number of checkboxes on that page...
The important thing is that they ALL have different name that goes like "check_box[number]"...

This way you won't get the only-one-selectable-form...

About the checking:

This while loop creates an variable $i that is the number of checkboxes indexes (that is number of checkbox fields - 1)...
You might want to know this number (if you don't already know it) and you might to put in an hidden field named, say "howMany" in order to know this value and to take it to form processing page... The value should be like $i or $total-1 or number of fields if you know it. Either will get you there...

On the form processing page you could do something like this to check if they are checked and to do whatever you want to do with them:

$i=0; //don't mistake this one with the previous $i because it is on other page
while($i<$howMany){
if($check-box[$i]!=""){//if it's checked
//do whatever with the value of it...
}
$i++;

}

Hope this helps...

bodzan
10-23-2003, 08:38 PM
umm, I made two mistakes in my previous reply... ^_^

If the name of the box is check_bow (instead of check_box I wanted) in the second while loop's if statement the variable you check is $check_bow (or check_box as I wanted) ...


HE HE HE