Another Checkbox Question

T

The Corinthian

I am quite new to ASP scripting and seem to be haveing no success with
checkboxes at all.

I have a sql database with bit datatypes and I am trying to create a asp
webform which will display and update the data from checkboxes.

Any help would be appreciated.

Rob
 
R

Ray Costanzo [MVP]

What exactly are you having trouble with?

<input type="checkbox"<% If rs.fields.item(0).value = 1 Then response.write
" checked"%>>

Ray at work
 
R

Rob

Hi,

I am probably mssing some thing I am creating my record set using the
following

data connection provided by inc file
<%
dim rs
dim strSQL




set rs=Server.CreateObject ("ADODB.Recordset")
strSQL = "SELECT ID, Arta, Corinthian, NewsLetter FROM preferences
WHERE ID ='" & _
(Session("userid")) & "'"


Set rs = objConn.Execute (strSQL)



%>

using



<input type="checkbox"<% If rs.fields.Item(Arta).value = 1 Then
response.write" checked"%>>



Returns
Error Type:
ADODB.Fields (0x800A0CC1)
Item cannot be found in the collection corresponding to the requested name
or ordinal.
/dbg12/prefs.asp, line 46
 
R

Ray Costanzo [MVP]

You've got it down just fine with just one small part. You forgot to put
"Arta" in quotes.

rs.Fields.Item("Arta").Value
''or alternatively
rs.Fields.Item(1).Value
'''Arta is the second column, so it has an index of 1. Column indexes start
at zero. So, ID has an index of 0, Arta is 1, Corinthian is 2, Newsletter
is 3.

I suggest that you get in the habit of using Option Explicit at the top of
all your VBS-based ASP pages. If you had Option Explicit, the error would
have been "Variable is not defined - Arta" or something along those lines.

Ray at work

Rob said:
Hi,

I am probably mssing some thing I am creating my record set using the
following
 
R

Rob

Ah sorted - thank you very very much


Ray Costanzo said:
You've got it down just fine with just one small part. You forgot to put
"Arta" in quotes.

rs.Fields.Item("Arta").Value
''or alternatively
rs.Fields.Item(1).Value
'''Arta is the second column, so it has an index of 1. Column indexes
start at zero. So, ID has an index of 0, Arta is 1, Corinthian is 2,
Newsletter is 3.

I suggest that you get in the habit of using Option Explicit at the top of
all your VBS-based ASP pages. If you had Option Explicit, the error would
have been "Variable is not defined - Arta" or something along those lines.

Ray at work
 
T

The Corinthian

I was a bit hasty there - the returning the values is fine now, but now I am
trying to update them.

using

strSQL = "UPDATE preferences SET"
strSQL = strSQL & "Arta Request.Form("Arta") & "'"
strSQL = strSQL & " WHERE ID = Session("UserID")"

but off course the value "ON" wont go into the bit field, how would I
convert it so it compatitble.

Many thanks again.

Rob
 
R

Ray Costanzo [MVP]

Give the checkbox a value of 1. Also, you have code enclosed in quotes
below.

<input name="chkArta" type="checkbox" value="1"<% If
CBool(rs.Fields.Item(1).Value) Then Response.Write " checked"%>>

And then in code:

<%
Dim iArta
iArta = Abs(CBool(Request.Form("chkArta")))
strSQL = "UPDATE preferences SET YourColumnNameHere = " & iArta & " WHERE
[ID] = " & Session("UserID")
RESPONSE.WRITE STRSQL
RESPONSE.END
%>

Ray at work
 
R

Rob

Many thanks yet again, I was nearly there, but didn't set a value nor did I
know about CBool.

Cheers again.

Rob

Ray Costanzo said:
Give the checkbox a value of 1. Also, you have code enclosed in quotes
below.

<input name="chkArta" type="checkbox" value="1"<% If
CBool(rs.Fields.Item(1).Value) Then Response.Write " checked"%>>

And then in code:

<%
Dim iArta
iArta = Abs(CBool(Request.Form("chkArta")))
strSQL = "UPDATE preferences SET YourColumnNameHere = " & iArta & " WHERE
[ID] = " & Session("UserID")
RESPONSE.WRITE STRSQL
RESPONSE.END
%>

Ray at work



The Corinthian said:
I was a bit hasty there - the returning the values is fine now, but now I
am trying to update them.

using

strSQL = "UPDATE preferences SET"
strSQL = strSQL & "Arta Request.Form("Arta") & "'"
strSQL = strSQL & " WHERE ID = Session("UserID")"

but off course the value "ON" wont go into the bit field, how would
I convert it so it compatitble.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top