Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 18th, 2004, 12:00 PM
Authorized User
 
Join Date: Sep 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Getting value of Dynamic Check boxes

Hi ya!

I hope someone can help me, i am creating an asp site and the problem is on one of my pages I have a dynamic table with info displayed and at the end of each row there is check box.

The value of the check box i have given the value of a field from the recoreset (The ID number),but now what i need to do is once one of the check boxes has been checked, i want to be able to get that ID number from the check box and pass it into the next page via the form..
I have tried several ways with no avail... its probably simple bt i have never cam across it before.....

Any help in the matter would be fab! Cheers ;)

 
Old March 18th, 2004, 03:10 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When you are rendering your page, fill in the value for each checkbox... as in the following example:

<form etc, etc...>
<input type="checkbox" name="your_checkbox_name" value="<%=rs.fields("ID")%>">
' ...
</form>

Now, I assume that you have more than one checkbox on your form...

When you post the form, Request("your_checkbox_name") will contain a comma delimited string of all of the values (IDs) that have been checked. If no checkboxes have been checked then Request("your_checkbox_name") will be an empty string.

You can parse the IDs using:

For Each ID_Value IN Split(Request("your_checkbox_name"),","))
  ' do something with each ID_Value here
  ' I like to use Trim(ID_Value) here to remove any leading or
  ' trailing space characters
Next

Hope that helps...

 
Old March 19th, 2004, 03:35 AM
Authorized User
 
Join Date: Sep 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, thanks fro your help so soon, I have tried the code you suggested this morning, however I am getting an error message of "object required"

Here's the code for th dynamic table (only 1 tick box will be chosen from however many is on the page (as its a dynamic number of check boxes depending on the number of records in the database))

<% if (not adoRS.BOF) and (not adoRS.EOF) then %>

<P align=center><STRONG>Select Relevant
Program</STRONG>:</P>
<P align=center><STRONG></STRONG></P>
<P>


<TABLE style="WIDTH: 532px; HEIGHT: 59px" border=1 align="center">

  <TR class=TableHeaderGrey>
    <TH width=50 align=middle><B>ID</B></TH>
    <TH width=450 align=middle ><B>Program Name</B></TH>
    <TH width=50 align=middle>Select</TH>
  </TR>


<%
    Do While Not (adoRS.EOF)
%>

    <TR class="<%=GetTableRowColor%>">
    <TD align=middle><%=adoRS.Fields(0).Value%></TD>

 <% gets data from database via VB DLL
  'get Program Description
  set objProject1 = Server.CreateObject("Project1.Class1")
  strProgramName = objProject1.GetProgramName(adoRS.Fields(0).Value)
  set objProject1 = nothing

  %>



    <TD align=middle><%=strProgramName%></TD>

Here are the dynamic check boxes:
    <TD align=middle><input id=chkProgram name="<%=adoRS.Fields(0).Value%>" type=checkbox onClick="DoCheckClick(this);"></TD>


</TR>
<%
 adoRS.MoveNext


loop

%>

</TABLE></P>



Maybe it applied your changes incorrectly... I thought i would have to implement some java script to pass the check box value into the form.....

Cheers very much for your help in advance! Kathryne

 
Old March 19th, 2004, 05:44 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I don't know what sort of values the recordset contains but you might be better modifying ther name of the checkbox:
Code:
><input id=chkProgram name="chk<%=adoRS.Fields(0).Value%>" type=checkbox onClick="DoCheckClick(this);">
Is "object expected" a server side error or client side? If client side it's probably because DoCheckClick is not available.

--

Joe





Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop over check boxes sams ASP.NET 1.0 and 1.1 Professional 5 July 17th, 2007 06:26 AM
Check Boxes Allan320 Access VBA 3 June 2nd, 2006 05:45 AM
Dynamic check boxes and select lists bsheridan Classic ASP Basics 1 March 17th, 2006 05:39 AM
Dynamic check boxes writing to database..help!! cincinnaticj7 Classic ASP Databases 0 January 25th, 2005 10:47 AM
Using check boxes in datagrid ractim ADO.NET 2 September 8th, 2004 08:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.