Categories > TinyButStrong general >

Dynamic Checkboxes

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Quati
Date: 2006-04-05
Time: 00:32

Dynamic Checkboxes

Sorry, but I search the forum for this topic, and the examples that are listed, doesn't work for me.

I need to create dynamic checkboxes with values from an array.

A stupid example:

the array comes with:
$array = array ('Apple', 'Orange', 'Lemon', 'Banana');

I want to create four dynamic checkboxes with that values. Something like:

<input type='checkbox' value='[blkFruits.val]' name='Fruits[]'>[blkFruits.val]

When I tried this, it only create the FIRST checkboxes (apple) and nothing more.

The result must be:

[ ] Apple
[ ] Orange
[ ] Lemon
[ ] Banana

How I can do that?

Thanks.
By: Sheepy
Date: 2006-04-05
Time: 12:43

Re: Dynamic Checkboxes

You need to make it a block:

<input type='checkbox' value='[blkFruits.val;block=input]' name='Fruits[]'>[blkFruits.val]</input>

Make sure you use MergeBlock instead of MergeField
By: Quati
Date: 2006-04-06
Time: 20:47

Re: Dynamic Checkboxes

Hi! This worked.

BUT, It shows the result:

[ ] apple [ ] orange [ ] lemon [ ] banana

And I need a <BR> after each checkbox...

How can I do it?

Thks
By: Quati
Date: 2006-04-06
Time: 20:55

Re: Dynamic Checkboxes

I MADE IT! :)

Here, the solution of the problem.

<input type='checkbox' value='[blkFruits.val;block=input]' name='Fruits[]'>[blkFruits.val;if [blkFruits.val]!=''; then '[blkFruits.val]<br>';]</input>
By: Quati
Date: 2006-04-07
Time: 00:17

Re: Dynamic Checkboxes

Ok. Now Im having ANOTHER problem.

I need to check if the checkbox is SELECTED or NOT.

What is the situation: I have the group of checkboxes (the fruits as mention) and I have another array with the fruits that are selected.

$array = array ('Apple', 'Orange', 'Lemon', 'Banana'); // the array that is use to do the checkbox construction
$selected_array = array ('Apple', 'Banana'); // the checkboxes selected

I need to make a function each time that the input code is created to verify if the input is selected or not, by doing a comparation between the input value just created (for example, the 'Apple' value) to the $selected_array. If the value exists in the $selected_array, so the checkbox is SELECTED, else NOT.

What can I do? I really try to find out this answer in the manual, but cant find it...

Thanks.
By: Sheepy
Date: 2006-04-10
Time: 05:49

Re: Dynamic Checkboxes

A hint: look at the 'multi-selection' part of this parameter's doc. ^_^

http://www.tinybutstrong.com/manual.php#html_field_prm_selected

You can also try the 'List, radio and checkbox' examples.