Forums
This topic is locked
Convert Checkboxes to text with commas
10 Jun 2003 23:43:04 Al Patel posted:
I am trying to something that seems very simple, but I can't figure it out. I have a form that has a group of checkboxes. For example, Jan, Feb, March, April, etc... (each as a checkbox). I write the Y/N values of each of these fields to an Access database.What I want to do next is where I am stuck. I need to spit out the checkboxes that were selected (Y value or whatever it needs to be), in text format with commas seperating them.
So for example, If checkboxes for April, July, December are selected. Then I would like to print:
'April, July, December'
on another web page when I query the DB. How do I do this? How do I also put a comma to seperate the months, and no comma before the first value and after the last?
I am building my site on Dreamweaver MX, ASP/VB, IIS, MS Access. Some direction would be greatly appreciated...
Replies
Replied 11 Jun 2003 14:21:45
11 Jun 2003 14:21:45 Owen Eastwick replied:
Set up the checkboxes as follows:
<input type="checkbox" name="chkMonth" value="January">
<input type="checkbox" name="chkMonth" value="February">
<input type="checkbox" name="chkMonth" value="March">
<input type="checkbox" name="chkMonth" value="April">
etc.
Notice that all the checkboxes have the same name.
Now collect the values:
varMonthsChecked = Request("chkMonth"
If all the checkboxes were ticked, varMonthsChecked would contain: January, February, March, April
Regards
Owen.
-------------------------------------------------------------------------------------------
Used programming books and web development software for sale (UK only): www.tdsf.co.uk/tdsfdemo/Shop.htm
Developer services and tutorials: www.drdev.net
Multiple Parameter UD4 / Access 2000 Search Tutorial: www.tdsf.co.uk/tdsfdemo/
<input type="checkbox" name="chkMonth" value="January">
<input type="checkbox" name="chkMonth" value="February">
<input type="checkbox" name="chkMonth" value="March">
<input type="checkbox" name="chkMonth" value="April">
etc.
Notice that all the checkboxes have the same name.
Now collect the values:
varMonthsChecked = Request("chkMonth"

If all the checkboxes were ticked, varMonthsChecked would contain: January, February, March, April
Regards
Owen.
-------------------------------------------------------------------------------------------
Used programming books and web development software for sale (UK only): www.tdsf.co.uk/tdsfdemo/Shop.htm
Developer services and tutorials: www.drdev.net
Multiple Parameter UD4 / Access 2000 Search Tutorial: www.tdsf.co.uk/tdsfdemo/
Replied 12 Jun 2003 15:10:55
12 Jun 2003 15:10:55 Al Patel replied:
Thanks for the tip Owen...
How do I insert the value of "varMonthsChecked" into my database after collecting the values?
Huh?
How do I insert the value of "varMonthsChecked" into my database after collecting the values?
Huh?
Replied 12 Jun 2003 15:47:39
12 Jun 2003 15:47:39 Julio Taylor replied:
stick them into a hidden field and create an insert record behaviour in your second page.
------------------------
Julio
PHP | MySQL | DWMX
ICQ: 19735247
MSN:
------------------------
Julio
PHP | MySQL | DWMX
ICQ: 19735247
MSN:
Replied 16 Jun 2003 04:01:56
16 Jun 2003 04:01:56 Al Patel replied:
Owen/Julio , thanks for the help.
One additional thing I need help with, along with this same scenario I am working on. How can I allow users to update this form later on, and have checkboxes show up with the previously selected values checked?
If all of my checkboxes have the same name, they all appear checked in the database. Thanks.
Huh?
One additional thing I need help with, along with this same scenario I am working on. How can I allow users to update this form later on, and have checkboxes show up with the previously selected values checked?
If all of my checkboxes have the same name, they all appear checked in the database. Thanks.
Huh?
Replied 16 Jun 2003 09:16:28
16 Jun 2003 09:16:28 Owen Eastwick replied:
If the comma delimited list is being stored in one field within the database then you could try something like this:
<% varMonths = RecordsetName.Fields.Item("Months"
.Value %>
<input type="checkbox" name="chkMonth" value="January" <% If InStr(varMonths, "January"
> 0 Then Response.Write("checked"
%>>
<input type="checkbox" name="chkMonth" value="February" <% If InStr(varMonths, "February"
> 0 Then Response.Write("checked"
%>>
<input type="checkbox" name="chkMonth" value="March" <% If InStr(varMonths, "March"
> 0 Then Response.Write("checked"
%>>
<input type="checkbox" name="chkMonth" value="April" <% If InStr(varMonths, "April"
> 0 Then Response.Write("checked"
%>>
etc.
Regards
Owen.
-------------------------------------------------------------------------------------------
Used programming books and web development software for sale (UK only): www.tdsf.co.uk/tdsfdemo/Shop.htm
Developer services and tutorials: www.drdev.net
Multiple Parameter UD4 / Access 2000 Search Tutorial: www.tdsf.co.uk/tdsfdemo/
<% varMonths = RecordsetName.Fields.Item("Months"

<input type="checkbox" name="chkMonth" value="January" <% If InStr(varMonths, "January"


<input type="checkbox" name="chkMonth" value="February" <% If InStr(varMonths, "February"


<input type="checkbox" name="chkMonth" value="March" <% If InStr(varMonths, "March"


<input type="checkbox" name="chkMonth" value="April" <% If InStr(varMonths, "April"


etc.
Regards
Owen.
-------------------------------------------------------------------------------------------
Used programming books and web development software for sale (UK only): www.tdsf.co.uk/tdsfdemo/Shop.htm
Developer services and tutorials: www.drdev.net
Multiple Parameter UD4 / Access 2000 Search Tutorial: www.tdsf.co.uk/tdsfdemo/