Forum Moderators: coopster

Message Too Old, No Replies

Tough One I Think

         

MarcoPolo

6:11 am on Mar 30, 2005 (gmt 0)

10+ Year Member



I have this form, well, a portion of a form:

<form>
<INPUT TYPE=checkbox NAME=catID[] VALUE="1">1
<INPUT TYPE=checkbox NAME=catID[] VALUE="2">2
<INPUT TYPE=checkbox NAME=catID[] VALUE="3">3
<INPUT TYPE=checkbox NAME=catID[] VALUE="4">4
<input type=submit yadda yadda yadda....

I can store the different values into one column, but if I pull this document up on the web again to edit it, how can I make those checkboxes that were checked originally display checked when I go to edit them?

Make sense?

coopster

11:29 am on Mar 30, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Loop over the POSTed form variable while building the list and compare the current value being assigned to the POSTed value(s) to see if you should mark the option as "checked" or not. Here are a couple of past threads that should get you started off in the right direction:

[webmasterworld.com...]
[webmasterworld.com...]
[webmasterworld.com...]

MarcoPolo

11:27 pm on Mar 30, 2005 (gmt 0)

10+ Year Member



Thanks for those links. I'm still a bit confused on how to make it work though so any help would be appreciated.

Here is what I'm trying to accomplish.

I have a table that has 2 columns.

ID, Selections

ID is simply an auto incrementing integer
Selections can be any, all, or none of the following: tree, shrub, bush

Selections contains (or doesn't contain) a set of information separated by commas.

Some data would include:

¦----------------------¦
¦ ID ¦ Selections ¦
¦====¦=================¦
¦ 1 ¦ tree,shrub,bush ¦
¦----+-----------------¦
¦ 2 ¦ bush ¦
¦----+-----------------¦
¦ 3 ¦ shrub, bush ¦
¦----------------------¦
(sorry about the mangled table... how can I force it to use a courier font?)

When I open the individual forms to edit them in HTML, how do I display all the checkboxes with the already selected checkboxes checked?

I have started with 2 arrays.

$selection (to represent all the possible choices)
$selected (to represent what is already selected)

I don't know how to go through each $selection and compare it to each $selected. If I could do that, I could easily assign a 'checked="checked"' value and echo that in the HTML.

Again, I went through those links you posted but I still can't seem to get it.