473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Populating checkboxes

I have a form with a list of checkboxes. The form is created dynamically from a database and the checkboxes are assigned to each item that is returned in the database (each item has a unique ID). I also have another database field which contains an array of numbers (eg. 1,2,33,34). How can I check the checkboxes in my dynamic form corresponding to the numbers in the array. eg. if the array is 1,2,33,34 how can boxes 1,2,33,34 be checked.

I am using ASP , and javascript

Thanks in advance
Apr 7 '07 #1
1 1248
jhardman
3,406 Expert 2GB
I would first assign the array of numbers to be checked to a variable:
Expand|Select|Wrap|Line Numbers
  1. dim checkedNumbers 
  2. checkedNumbers = split (objRS("selectedFields"), ",")
  3. 'checkedNumbers(0) now equals "1" , checkedNumbers(1) = "2" etc.
  4.  
Then as I make the list of checkboxes I would check each ID against the checkedNumbers array:
Expand|Select|Wrap|Line Numbers
  1. dim i
  2. i = 0
  3. do until objRS.eof %>
  4.    <li><%=objRS("ID")%> <input type="checkbox" name="<%=objRS("ID")%>
  5.    <%
  6.    if cstr(objRS("ID")) = checkedNumbers(i) then
  7.       response.write "checked"
  8.       i = i + 1
  9.    end if %>
  10.    ></li>
  11.    <%
  12.    objRS.moveNext
  13. loop
  14.  
Of course this will only work if the array is in the same order as the records you are checking. The other way to do it would be to place the array in a single variable:
Expand|Select|Wrap|Line Numbers
  1. dim checkedNumbers 
  2. checkedNumbers = "," & objRS("selectedFields")& ","
then the logical statement becomes:
Expand|Select|Wrap|Line Numbers
  1.    if instr(checkedNumbers, "," & cstr(objRS("ID")) & ",")>0 then
Does this make sense?

Jared
Apr 10 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Suzanne | last post by:
Hi, I have a form which our clients can fill in with their personal details. As part of the information we store there is a section - areas of interest - this is a number of radio buttons. ...
3
by: Robert | last post by:
Developing a form that has multiple controls; TextBoxes, RadioButtons, CheckBoxes, etc. I want to dynamically populate all the controls from the database and scroll through the data row by row. ...
4
by: Lumpierbritches | last post by:
Thank you once again for any and all assistance. I'm building an application that's getting quite bulky due to the number of forms, macros and procedures. I was wondering if there's a way to use 1...
3
by: Jay | last post by:
I have an asp.net application that needs to fill a series of checkboxes with usernames from a particular group in Active Directory. Could someone please point me in the right direction in regards...
3
by: RFS666 | last post by:
Hello together, I tried to find out about populating an asp.net server control (a dropdownlist) from the clientside jscript, but I didn't find a solution up to now. I cannot use a html...
6
by: JackM | last post by:
I have a multiple select input in a form that's being populated by a row from my database as such: <input type=\"checkbox\" name=\"subm\" value=\"$row\"> That part is working fine as I can check...
2
by: Phil Sandler | last post by:
I am trying to do something which seems (to me) to be very simple, and yet I can't seem to figure it out. I have a gridview and a formview. When a user clicks "select" in the gridview, the...
3
by: parkergirl | last post by:
Hi, I have an msflexgrid that I need to select with checkboxes (I'm currently using WingDings font). The selection of rows cannot be anymore than three rows (randomly). Then, I need to take the...
1
by: =?Utf-8?B?VGFtbXk=?= | last post by:
Hi! I am using VB 2008 with SQL Server 2000 and SQL Server 2005 (depending which server the user selects to connect to). I have a combox in which the user types the server to connect to. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.