473,396 Members | 2,111 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,396 software developers and data experts.

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 adOpenForwardOnly, adLockReadOnly
dim adCmdTable, ctr, checkboxID
adOpenForwardOnly = 0
adLockReadOnly = 1
adCmdTable = 2

dim objConn, objRS, cmdType

set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open("tanklink")
set objCommand = Server.CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConn
objCommand.CommandType = 1
objCommand.CommandTimeout = 10
objCommand.CommandText = Session("newSQL")

objCommandType = adCmdText
set objRS = objCommand.Execute

while not objRS.EOF
ctr = ctr + 1
checkboxID = "tank_chkbox"
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 1863
> 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.form("tank_chkbox"), ",")

'iterate through form field
For i = 0 to request.form("tank_chkbox").count 'may need to start with 1
instead of 0
value = request.form("tank_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.com...
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 adOpenForwardOnly, adLockReadOnly
dim adCmdTable, ctr, checkboxID
adOpenForwardOnly = 0
adLockReadOnly = 1
adCmdTable = 2

dim objConn, objRS, cmdType

set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open("tanklink")
set objCommand = Server.CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConn
objCommand.CommandType = 1
objCommand.CommandTimeout = 10
objCommand.CommandText = Session("newSQL")

objCommandType = adCmdText
set objRS = objCommand.Execute

while not objRS.EOF
ctr = ctr + 1
checkboxID = "tank_chkbox"
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="JavaScript">
function display_checkbox_values()
{
var selected_list;
selected_list = Response.Form("tank_chkbox");
alert(selected_list);
}
</script>
<td><INPUT type="submit" onclick="display_checkbox_values()"
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*****@ielearning.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.form("tank_chkbox"), ",")

'iterate through form field
For i = 0 to request.form("tank_chkbox").count 'may need to start with 1
instead of 0
value = request.form("tank_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.Form("tank_chkbox")%>";

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


<Rodney King> wrote in message
news:hd********************************@4ax.com...
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="JavaScript">
function display_checkbox_values()
{
var selected_list;
selected_list = Response.Form("tank_chkbox");
alert(selected_list);
}
</script>
<td><INPUT type="submit" onclick="display_checkbox_values()"
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*****@ielearning.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.form("tank_chkbox"), ",")

'iterate through form field
For i = 0 to request.form("tank_chkbox").count 'may need to start with 1
instead of 0
value = request.form("tank_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="JavaScript">
function display_checkbox_values()
{
var selected_list = "<%=Request.Form("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*****@dnartreb.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.Form("tank_chkbox")%>";


Jul 19 '05 #6
Ah, I see. Once again, you are confusing server-side and client-side
script. Request.Form("anything") 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.com...
Thanks Aaron,

I modified my JavaScript so that it looks like this:

<script language="JavaScript">
function display_checkbox_values()
{
var selected_list = "<%=Request.Form("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*****@dnartreb.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.Form("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*****@dnartreb.noraa> wrote:
Ah, I see. Once again, you are confusing server-side and client-side
script. Request.Form("anything") 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
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)) {...
9
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 =...
5
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; }...
1
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...
5
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...
1
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...
1
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...
2
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...
0
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....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.