473,695 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Desperately: Need help selecting a checkbox

Hi,

I have developed an ASP page which dynamically displays a list of
checkbox options based on a SQL statement. Here is my code:

<div style="OVERFLOW :auto; Height: 150px">
<table>
<%
dim adOpenForwardOn ly, adLockReadOnly
dim adCmdTable, ctr, checkboxID
adOpenForwardOn ly = 0
adLockReadOnly = 1
adCmdTable = 2

dim objConn, objRS, cmdType

set objConn = Server.CreateOb ject("ADODB.Con nection")
objConn.Open("t anklink")
set objCommand = Server.CreateOb ject("ADODB.Com mand")
objCommand.Acti veConnection = objConn
objCommand.Comm andType = 1
objCommand.Comm andTimeout = 10
objCommand.Comm andText = Session("newSQL ")

objCommandType = adCmdText
set objRS = objCommand.Exec ute

while not objRS.EOF
ctr = ctr + 1
checkboxID = "tank_chkbo x"
Response.Write "<tr>"
Response.Write "<td width='20px'>"
Response.Write "<input type='checkbox' name='"
& checkboxID & "' id='" & checkboxID & "' value='" & objRS("tankid")
&"' />"
Response.Write "</td>"
Response.Write "<td width='200px'>"
Response.Write objRS("Name")
Response.Write "</td>"
Response.Write "</tr>"
objRS.MoveNext
wend
objRS.Close
objConn.Close
set objRS = Nothing
set objConn = Nothing
%>
</table>
</div>

My code displays properly, but I am having trouble writing a function
or a procedure that will parse through the list of checkboxes to see
which checkbox is checked when a submit button is pressed. Can
someone please provide some sample code to get me started?

Response.Form(" tank_chkbox") does not seem to work and gives me an
error when I try and use it.

Thanks

Jul 19 '05 #1
7 1870
> Response.Form(" tank_chkbox") does not seem to work and gives me an
error when I try and use it.


What does "does not seem to work" mean? What is "an error", could you be
more specific? What does "try and use it" mean, can you show what code
you've tried?

--
http://www.aspfaq.com/
(Reverse address to reply.)
Jul 19 '05 #2
It appears from your code that the checkbox name is the same in all cases.
Is that your intent or were you planning to append the count in ctr to each
name.

If the checkboxes are all the same name then you will receive a
comma-separated list of the values for all the "checked" boxes. You can
access the individual values by splitting the list on comma or by iterating
through the form collection as in:

'split into array
avalues = split(request.f orm("tank_chkbo x"), ",")

'iterate through form field
For i = 0 to request.form("t ank_chkbox").co unt 'may need to start with 1
instead of 0
value = request.form("t ank_chkbox")(i)

'do something with value
Next

Note: if your values may contain commas then you will need to use the
request.form method instead of split

If you are going to append the counter then you will need to loop through
the possible counter values and check for form fields.

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com
<Rodney King> wrote in message
news:s3******** *************** *********@4ax.c om...
Hi,

I have developed an ASP page which dynamically displays a list of
checkbox options based on a SQL statement. Here is my code:

<div style="OVERFLOW :auto; Height: 150px">
<table>
<%
dim adOpenForwardOn ly, adLockReadOnly
dim adCmdTable, ctr, checkboxID
adOpenForwardOn ly = 0
adLockReadOnly = 1
adCmdTable = 2

dim objConn, objRS, cmdType

set objConn = Server.CreateOb ject("ADODB.Con nection")
objConn.Open("t anklink")
set objCommand = Server.CreateOb ject("ADODB.Com mand")
objCommand.Acti veConnection = objConn
objCommand.Comm andType = 1
objCommand.Comm andTimeout = 10
objCommand.Comm andText = Session("newSQL ")

objCommandType = adCmdText
set objRS = objCommand.Exec ute

while not objRS.EOF
ctr = ctr + 1
checkboxID = "tank_chkbo x"
Response.Write "<tr>"
Response.Write "<td width='20px'>"
Response.Write "<input type='checkbox' name='"
& checkboxID & "' id='" & checkboxID & "' value='" & objRS("tankid")
&"' />"
Response.Write "</td>"
Response.Write "<td width='200px'>"
Response.Write objRS("Name")
Response.Write "</td>"
Response.Write "</tr>"
objRS.MoveNext
wend
objRS.Close
objConn.Close
set objRS = Nothing
set objConn = Nothing
%>
</table>
</div>

My code displays properly, but I am having trouble writing a function
or a procedure that will parse through the list of checkboxes to see
which checkbox is checked when a submit button is pressed. Can
someone please provide some sample code to get me started?

Response.Form(" tank_chkbox") does not seem to work and gives me an
error when I try and use it.

Thanks

Jul 19 '05 #3
Mark,

Thanks for responding. My problem is I can't even get the comma
seperated list. I'm very familiar with ASP.NET but am new to ASP and
JavaScript. What I essentially want to do is to have a submit button
onclick event iterate through the table collection that I created and
select the values of my checked checkboxes.

Here is the code I have for my submit button and function:
<script language="JavaS cript">
function display_checkbo x_values()
{
var selected_list;
selected_list = Response.Form(" tank_chkbox");
alert(selected_ list);
}
</script>
<td><INPUT type="submit" onclick="displa y_checkbox_valu es()"
id=submit1 name=submit1>
</td>

When this code is run, it gives me an error.

Aaron,

Thanks for responding. The error message that I am getting is
Response is not defined.
Thanks for all your help.

On Tue, 12 Oct 2004 13:46:37 -0700, "Mark Schupp"
<ms*****@ielear ning.com> wrote:
It appears from your code that the checkbox name is the same in all cases.
Is that your intent or were you planning to append the count in ctr to each
name.

If the checkboxes are all the same name then you will receive a
comma-separated list of the values for all the "checked" boxes. You can
access the individual values by splitting the list on comma or by iterating
through the form collection as in:

'split into array
avalues = split(request.f orm("tank_chkbo x"), ",")

'iterate through form field
For i = 0 to request.form("t ank_chkbox").co unt 'may need to start with 1
instead of 0
value = request.form("t ank_chkbox")(i)

'do something with value
Next

Note: if your values may contain commas then you will need to use the
request.form method instead of split

If you are going to append the counter then you will need to loop through
the possible counter values and check for form fields.


Jul 19 '05 #4
(a) there is no such thing as response.form
(b) you are mixing client-side and server-side script. Maybe you meant:

var selected_list = "<%=Request.For m("tank_chkbox" )%>";

--
http://www.aspfaq.com/
(Reverse address to reply.)


<Rodney King> wrote in message
news:hd******** *************** *********@4ax.c om...
Mark,

Thanks for responding. My problem is I can't even get the comma
seperated list. I'm very familiar with ASP.NET but am new to ASP and
JavaScript. What I essentially want to do is to have a submit button
onclick event iterate through the table collection that I created and
select the values of my checked checkboxes.

Here is the code I have for my submit button and function:
<script language="JavaS cript">
function display_checkbo x_values()
{
var selected_list;
selected_list = Response.Form(" tank_chkbox");
alert(selected_ list);
}
</script>
<td><INPUT type="submit" onclick="displa y_checkbox_valu es()"
id=submit1 name=submit1>
</td>

When this code is run, it gives me an error.

Aaron,

Thanks for responding. The error message that I am getting is
Response is not defined.
Thanks for all your help.

On Tue, 12 Oct 2004 13:46:37 -0700, "Mark Schupp"
<ms*****@ielear ning.com> wrote:
It appears from your code that the checkbox name is the same in all cases.Is that your intent or were you planning to append the count in ctr to eachname.

If the checkboxes are all the same name then you will receive a
comma-separated list of the values for all the "checked" boxes. You can
access the individual values by splitting the list on comma or by iteratingthrough the form collection as in:

'split into array
avalues = split(request.f orm("tank_chkbo x"), ",")

'iterate through form field
For i = 0 to request.form("t ank_chkbox").co unt 'may need to start with 1
instead of 0
value = request.form("t ank_chkbox")(i)

'do something with value
Next

Note: if your values may contain commas then you will need to use the
request.form method instead of split

If you are going to append the counter then you will need to loop through
the possible counter values and check for form fields.

Jul 19 '05 #5
Thanks Aaron,

I modified my JavaScript so that it looks like this:

<script language="JavaS cript">
function display_checkbo x_values()
{
var selected_list = "<%=Request.For m("tank_chkbox" )%>";
alert(selected_ list);
}
</script>

When I click on my submit button I no longer get an error message but
my alert window never fires. For now I just want to see if I'm
capturing anything.

Thanks
On Wed, 13 Oct 2004 09:53:31 -0400, "Aaron [SQL Server MVP]"
<te*****@dnartr eb.noraa> wrote:
(a) there is no such thing as response.form
(b) you are mixing client-side and server-side script. Maybe you meant:

var selected_list = "<%=Request.For m("tank_chkbox" )%>";


Jul 19 '05 #6
Ah, I see. Once again, you are confusing server-side and client-side
script. Request.Form("a nything") will not be available until you actually
submit the form, so you can only do your alert on the receiving page (not on
the same page that holds the checkboxes). You will need to use client-side
script if you want to alert which checkboxes are checked BEFORE submitting
the form.

--
http://www.aspfaq.com/
(Reverse address to reply.)


<Rodney King> wrote in message
news:vr******** *************** *********@4ax.c om...
Thanks Aaron,

I modified my JavaScript so that it looks like this:

<script language="JavaS cript">
function display_checkbo x_values()
{
var selected_list = "<%=Request.For m("tank_chkbox" )%>";
alert(selected_ list);
}
</script>

When I click on my submit button I no longer get an error message but
my alert window never fires. For now I just want to see if I'm
capturing anything.

Thanks
On Wed, 13 Oct 2004 09:53:31 -0400, "Aaron [SQL Server MVP]"
<te*****@dnartr eb.noraa> wrote:
(a) there is no such thing as response.form
(b) you are mixing client-side and server-side script. Maybe you meant:

var selected_list = "<%=Request.For m("tank_chkbox" )%>";

Jul 19 '05 #7
Thanks alot Aaron. That really helped. I'm finally beginning to get
it. :)
On Wed, 13 Oct 2004 11:20:16 -0400, "Aaron [SQL Server MVP]"
<te*****@dnartr eb.noraa> wrote:
Ah, I see. Once again, you are confusing server-side and client-side
script. Request.Form("a nything") will not be available until you actually
submit the form, so you can only do your alert on the receiving page (not on
the same page that holds the checkboxes). You will need to use client-side
script if you want to alert which checkboxes are checked BEFORE submitting
the form.


Jul 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3718
by: Franco Fellico' | last post by:
Hi everybody. Suppose to have a table dinamically created in a form where I show some information of a set of row selected in a db-table: ....... while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td> <inputtype=\"checkbox\"name=\"checkbox$cnt\"value=\"checkbox\"
9
4643
by: Phil Powell | last post by:
I am producing a form using PHP on the back end and Javascript on the front end. The resulting script will come to the browser as follows: <script> <!-- function selectAll() { moveElement = eval("document.imageForm.move" + ""); alert(moveElement); if (document.imageForm.select_all.checked) {
5
22937
by: Jez | last post by:
Hi, I have created the following functions to select and deselect checkboxes in a form ... function check(checkbox) { for (i = 0; i < checkbox.length; i++) { checkbox.checked = true; } return "Select all";
1
17457
by: Eric | last post by:
Hi all, I have a form that generates a dynamic number of rows from a value passed in via querystring. I have a one static row in my form with a "master" checkbox that I have deemed "Select All:". I want to be able to select all and deselect all the other checkboxes beneath it in the column by clicking on it. I've gotten it partially working. I can click the "master" checkbox and it will set the .checked property of all the others to...
5
1544
by: Dave | last post by:
Hi all, Apologies if this is the wrong group. I have done a search on google but my keywords are probably no good. What I want to do is to display a list of data in a datagrid (which I have already done). At the side of the list, I want to put in a checkbox, basically to select that line.
1
2913
by: sneha123 | last post by:
There will be some 20 questions and for each question there will be 4 choices.what i want to do is to select multiple answers by clicking the checkbox. i m using asp.net,vb.net pls help me we have written the code using radio button for selecting single item.but we want to replace it with checkbox to select multiple items. the code using radio button is given below .pls correct it with checkbox
1
3346
by: Bob Loveshade | last post by:
I am looking for an example that shows how to select and highlight multiple rows in a DataGrid. My DataGrid is part of a Web User Control which is contained in an ASPX page. I haven't been able to find any examples which demonstrate how to do this. My Code:
2
1620
by: engwar1 | last post by:
I'm a .Net newbie and have started writing a Windows Forms application to assist me in choosing files/directories to move from one drive to another. Basically what I want is something like the TreeView control and have the following questions. + I'm not sure if it's possible to include a checkbox control as part of a TreeView. Do I need to use images of a checkbox in my ImageIndex property? I'd imaging I'd need 4 images of directories...
0
1886
by: san1014 | last post by:
Hi to all' I am using Java swings. I written a code to display a table. In the table i used Boolean.class type column. when i click the checkbox it value to be change from false to true. please help me . iam sending my code here CODE: package classes;
0
8574
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9116
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8990
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8850
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8829
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5839
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4342
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2276
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.