Dynamic Checkboxes ASP and Access

Results 1 to 2 of 2

Thread: Dynamic Checkboxes ASP and Access

  1. #1
    Join Date
    Dec 1969

    Default Dynamic Checkboxes ASP and Access

    I have a contact list in an Access database.<BR><BR>I have a table that contains contacts, a table that contains categories, and a third table that is a join table that assigns users to categories in a many-to-many relationship.<BR><BR>I have a script that creates a series of checkboxes from the categories table so when a new contact is added the user can select multiple checkboxes, categories, to place the user into.<BR><BR>I want to be able to edit a contact by clicking their name that takes them to a ContactUpdate.asp form that is already filled with all of the values for the contact. Their name, address, phone number etc. however I want the checkboxes,categories, that the contact is already in to be selected on the ContactUpdate.asp page.<BR><BR>I need the user to know what categories the contact is already in. Plus display all the categories the contact is NOT in.<BR><BR>Here is a sample of what the page currently looks like:<BR>http://heliocreative.com/display.htm<BR><BR>The Checkboxes are all created dynamically I just need to mark checked those categories the user has already been addded to. <BR><BR>Here is the code that selects the categories from the database and then formats them into 4 columns of checkboxes:<BR><BR>&#060;%<BR>&#039;--Declare variables<BR>Dim SQLSTR, objRS, arrCategories, DisplayCategory, LinkID, RowCounter, DisplayName, ColCounter, NumRows, NumRecords, Category<BR><BR>&#039;--Change this constant to tell it how many columns in which to display the table<BR>Const NumColumns = 3 <BR><BR>&#039;--Open connection to SQL Server database containing category records<BR><BR><BR>SQLSTR = "SELECT * FROM tblCategory ORDER BY Category"<BR><BR>&#039;--Open recordset and then use GetRows to move it into the array<BR>Set objRS = Server.CreateObject("ADODB.Recordset")<BR>objRS.Op en SQLSTR, oCm, 3, 3<BR>arrCategories = objRS.getrows<BR><BR>&#039;--Close and terminate connection and recordset objects<BR>objRS.close<BR>set objRS = nothing<BR>%&#062;<BR><BR>&#060;table ALIGN="CENTER" BORDER="0" CELLPADDING="1" CELLSPACING="3" width="400"&#062;<BR>&#060;%<BR>&#039;-- Find out how many records are in the array (Add 1 since array coordinate starts at 0)<BR>NumRecords = ubound(arrCategories,2) + 1<BR><BR>&#039;--Calculates how many rows there should be based on the specified number of columns<BR>&#039;--The last column will always the the short column if there is one<BR>if NumRecords mod NumColumns = 0 then<BR> NumRows = NumRecordsNumColumns<BR>Else<BR> NumRows = NumRecordsNumColumns + 1<BR>End if <BR><BR><BR>&#039;--The outer loop walks down the rows<BR>for RowCounter = 1 to NumRows<BR> <BR> &#039;--The inner loop steps across the columns<BR> For ColCounter = 0 to NumColumns-1<BR> <BR> if RowCounter + ColCounter * NumRows &#060;= NumRecords then<BR> &#039;--Build the display name <BR>DisplayCategory = arrCategories(1, RowCounter + ColCounter * NumRows-1)<BR>LinkID = arrCategories(0, RowCounter + ColCounter * NumRows-1)<BR>%&#062;<BR> <BR> &#060;%<BR> &#039;--Write out the display name as a link to the detail page<BR> response.write "&#060;td&#062;&#060;input type=""checkbox"" name=""categoriesChecked"" value="& LinkID &"&#062;&#060;font face=""Arial, Helvetica, sans-serif"" size=""1""&#062;"& DisplayCategory & "&#060;/font&#062;&#060;/td&#062;"<BR> Else<BR> &#039;--This condition takes care of the case where your last column has fewer rows than the first one <BR> Response.write "&#060;td&#062; &#060;/td&#062;"<BR> end if <BR> Next<BR><BR>response.write "&#060;/tr&#062;"<BR><BR>Next%&#062;

  2. #2
    Join Date
    Dec 1969

    Default RE: Dynamic Checkboxes ASP and Access

    looks good but are why are all value="n/a" in the resulting source?<BR><BR>Is this what you store in the database?<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts