# Dynamic Checkboxes

**URL:** <https://forum.servoy.com/t/dynamic-checkboxes/9045>\
**Category:** Classic Servoy\
**Created:** [April 28, 2008, 4:55pm UTC](https://forum.servoy.com/t/dynamic-checkboxes/9045 "2008-04-28T16:55:34Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![darthtall](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@darthtall](https://forum.servoy.com/u/darthtall)\
**Post date:** [April 28, 2008, 4:55pm UTC](https://forum.servoy.com/t/dynamic-checkboxes/9045/1 "2008-04-28T16:55:34Z")

</div>

I would like to show the user a list of records from table and allow the user to select which records to include with a new record in a new database.

I will create a new record for each item checked in the list. I have included a quick sample of an html style form that I would like to do in Servoy…

==============================================  
var my\_html = “”;  
my\_html = my\_html + “”;

my\_html = my\_html + “”;  
my\_html = my\_html + “Form Name”;  
my\_html = my\_html + “Form Description”;  
my\_html = my\_html + “Include This Form”;  
my\_html = my\_html + “”

for ( var i = 1 ; i \<= controller.getMaxRecordIndex() ; i++ )  
{  
controller.setSelectedIndex(i);  
my\_html = my\_html + “”;  
my\_html = my\_html + “” + template\_name + “”;  
my\_html = my\_html + “” + description + “”;  
my\_html = my\_html + "\<input type=checkbox “;  
my\_html = my\_html + “name=template\_” + i + " value=ON\>”;  
my\_html = my\_html + “”;

}

my\_html = my\_html + “”;

# controller.setDataProviderValue(‘globals.my\_html’,my\_html);

I want to grab the user inputs and save the record in a new table by spliting the submitted values. Any thoughts greatly appreciated.

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [April 28, 2008, 5:51pm UTC](https://forum.servoy.com/t/dynamic-checkboxes/9045/2 "2008-04-28T17:51:56Z")

</div>

Hi darthtall,

First of all welcome to the forum. I see it’s your first post.

Your approach won’t work since the HTML will be rendered in memory and any changes to the values too.  
What you can do is to use a dynamic value list attached to a checkbox field.  
Only downside is that you can’t have a custom value list per record in a list/table view.  
Another option would be to use the HTML to only show the values in an non-editable field and using a edit dialog to edit this field using a custom value list.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![darthtall](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@darthtall](https://forum.servoy.com/u/darthtall)\
**Post date:** [April 28, 2008, 6:01pm UTC](https://forum.servoy.com/t/dynamic-checkboxes/9045/3 "2008-04-28T18:01:27Z")

</div>

Thanks Rob.

I had hope to create dynamic check boxes based on a list view. To bad you can not submit the html to a form. I can do this in .net with a great deal of code. Had hope that I could create dynamic check boxes to store the choices later… Looks like I may have to rethink my approach

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [April 28, 2008, 6:11pm UTC](https://forum.servoy.com/t/dynamic-checkboxes/9045/4 "2008-04-28T18:11:20Z")

</div>

Hi darthtall,

> darthtall:  
> I had hope to create dynamic check boxes based on a list view. To bad you can not submit the html to a form. I can do this in .net with a great deal of code. Had hope that I could create dynamic check boxes to store the choices later… Looks like I may have to rethink my approach

Well you could do it with little less code but still a workaround nevertheless.  
Use a headless client/Webclient and load that in a HTML area of the Rich client. But there are a few downsides on this approach like the use of extra client licenses. Or you can use a headless client and bind that to the application, therefore only using 1 license for all users. But it won’t be multithreading and use of globals and such is not recommend then.  
Of course you could use another technology to serve the HTML but then you won’t have the data broadcasting of the changes to other clients.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![darthtall](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@darthtall](https://forum.servoy.com/u/darthtall)\
**Post date:** [April 28, 2008, 10:02pm UTC](https://forum.servoy.com/t/dynamic-checkboxes/9045/5 "2008-04-28T22:02:28Z")

</div>

# ============== Form in asp
\<% Set Conn = Server.CreateObject("ADODB.Connection") Set rs = Server.CreateObject("ADODB.Recordset") Conn.Open "DSN=Thing;" strSQL = "SELECT \* FROM things" rs.Open strSQL, Conn %\>

| Package Name 

Package Desc

 |
| 

\<%  
a=1  
do until rs.EOF  
desc = rs(“description”)  
id = rs(“Template\_ID”)  
name = rs(“template\_name”)  
%\>

  
\<%  
a = a + 1  
rs.MoveNext  
%\>

\<% loop rs.close Conn.close set rs = nothing set conn = nothing %\>

| Form Name | Form Desc | Include? |
| \<%=name%\> | \<%=desc%\> | 

 |

 |

 =========== END FORM
# ====================== Form Processing page

\<%  
package\_name = request.form(“package\_name”)  
package\_desc = request.form(“package\_desc”)

my\_var = request.form(“template”)

my\_var2 = split(my\_var,“|”)

Max = Ubound(my\_var2)-1

For i = 0 to Max

'For i = 0 to Ubound(my\_var2)

my\_var3 = my\_var2(i)

my\_test = InStr(my\_var3,“ON”)

if my\_test \> 0 then  
my\_var4 = split(my\_var3,“,”)

for a = 0 to Ubound(my\_var4)

if Len(my\_var4(a)) \> 0 then

if i = 0 then  
if a = 1 then

my\_sql = “”  
my\_sql = my\_sql & “UPDATE pdf\_package\_template\_instance SET pdf\_package\_template\_instance.pti\_name='” & package\_name & “',”  
my\_sql = my\_sql & “pdf\_package\_template\_instance.pti\_desc='” & package\_desc & “',”  
my\_sql = my\_sql & “pdf\_package\_template\_instance.template\_id=” & my\_var4(a) & “;”  
response.write my\_sql & "  
"  
my\_sql = “”  
end if  
else  
if a = 2 then

my\_sql = “”  
my\_sql = my\_sql & “UPDATE pdf\_package\_template\_instance SET pdf\_package\_template\_instance.pti\_name='” & package\_name & “',”  
my\_sql = my\_sql & “pdf\_package\_template\_instance.pti\_desc='” & package\_desc & “',”  
my\_sql = my\_sql & “pdf\_package\_template\_instance.template\_id=” & Trim(my\_var4(a)) & “;”  
response.write my\_sql & "  
"  
my\_sql = “”  
end if  
end if  
end if

next

end if

next

%\>

=============

END PROCESS

-===================

now to do this in servoy…

with a bean for the selection list maybe and then process the selections on a button any help greatly appreciated.

Coming from .net world no Java prog exp at all… so be gentle

---

<div class="post-metadata">

**Author:** ![Jan\_Blok](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@Jan\_Blok](https://forum.servoy.com/u/Jan_Blok)\
**Post date:** [April 30, 2008, 1:18pm UTC](https://forum.servoy.com/t/dynamic-checkboxes/9045/6 "2008-04-30T13:18:46Z")

</div>

As Robert suggested the most easy way to get this done is:

1. create custom valuelist (leave empty)
2. attach valuelist to field with displaytype “check”  
2a) attach global variable as dataprovider
3. via scripting fill the valuelist with application.setValuelistItems(…) see sample how to use this
4. make a separate button method to process the selected actions while reading the global

---

<div class="post-metadata">

**Author:** ![diana.bodnarescu](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@diana.bodnarescu](https://forum.servoy.com/u/diana.bodnarescu)\
**Post date:** [December 10, 2008, 8:37am UTC](https://forum.servoy.com/t/dynamic-checkboxes/9045/7 "2008-12-10T08:37:34Z")

</div>

Hello,  
I am facing the same problem and I followed your steps that are written above, but I couldn’t continue with step 4 (make a separate button method to process the selected actions while reading the global) because even if they are checkboxes, i can only select 1 value. Or did I get it wrong? I am using Servoy 3.5.7. Thanks in advance.

DB

---

<div class="post-metadata">

**Author:** ![Jan\_Blok](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@Jan\_Blok](https://forum.servoy.com/u/Jan_Blok)\
**Post date:** [December 10, 2008, 9:56am UTC](https://forum.servoy.com/t/dynamic-checkboxes/9045/8 "2008-12-10T09:56:36Z")

</div>

> diana.bodnarescu:  
> i can only select 1 value

To be able to select multiple values, you underlaying dataprovider must be of type text

---

<div class="post-metadata">

**Author:** ![diana.bodnarescu](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@diana.bodnarescu](https://forum.servoy.com/u/diana.bodnarescu)\
**Post date:** [December 10, 2008, 11:50am UTC](https://forum.servoy.com/t/dynamic-checkboxes/9045/9 "2008-12-10T11:50:54Z")

</div>

Thank you for your answer!  
It works if the dataprovider (a global variable) is text. Could you please tell me if there is a way to preselect the checkboxes?

D.B.

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [December 10, 2008, 12:34pm UTC](https://forum.servoy.com/t/dynamic-checkboxes/9045/10 "2008-12-10T12:34:22Z")

</div>

Hi Diana,

Your question is answered in [viewtopic.php?t=11706](http://forum.servoy.com/viewtopic.php?t=11706) .  
Please post a question only in 1 thread.

---

<div class="post-metadata">

**Author:** ![agiletortoise](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@agiletortoise](https://forum.servoy.com/u/agiletortoise)\
**Post date:** [December 10, 2008, 2:18pm UTC](https://forum.servoy.com/t/dynamic-checkboxes/9045/11 "2008-12-10T14:18:15Z")

</div>

This is exactly the problem I’ve been working on solving with the solutionModel this week. I’m not all the way there yet, but the new 4.1 feature to base a form on a dataset works nicely for this type of thing.

```auto
	var q = "SELECT resource_id, resource_name, 0 AS 'is_selected' FROM resources \
				WHERE is_active = 1 ORDER BY resource_name asc";
	var ds = databaseManager.getDataSetByQuery('cfbs',q,[],-1);
	var fds = ds.createDataSource('resource_select_data',[DM_COLUMNTYPE.INTEGER,DM_COLUMNTYPE.TEXT,DM_COLUMNTYPE.INTEGER]);

	var frmName = 'resource_select_dialog';
	solutionModel.removeForm(frmName);
	var frm = solutionModel.newForm('resource_select_dialog',fds,'cfbs_main',false,250,250);

	frm.scrollbars = SM_SCROLLBAR.HORIZONTAL_SCROLLBAR_NEVER;
	frm.view = SM_VIEW.LOCKED_TABLE_VIEW;
	
	var lbl = frm.newLabel('temp',20,30,100,23);
	lbl.dataProviderID = 'resource_name';
	lbl.anchors = SM_ANCHOR.ALL;
	
	var chk = frm.newCheck('is_selected',20,40,23,23);

```

I’ve then built a form with the a dynamic dataset with a column for the checkbox that is not in the database. If I show the form, I can check the boxes for the lines I want – then I will have to parse out the items checked.

I’m still in-process on this, but it seems to be working out nicely.

greg.
