473,785 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to get a checkbox checked when loading the page?

Hi,

I have a input with type checkbox. I want it to be automatically checked if
the value from the corresponding field in the database is also checked.
I tried this:
<%
set objdc = Server.CreateOb ject("ADODB.Con nection")
etc ...
sql="select maa13 from mytable"
dim rsArray
Set rs = objdc.execute(s ql)
if not rs.eof then
rsArray = rs.GetRows()
rec = UBound(rsArray, 2) + 1
rs.movefirst
....
%>
<html><body>
<input id="in100" name="maa13" type="checkbox"
value="<%=rs.Fi elds("maa13").V alue%>>
.....

but nothing happens!
I can do this in Javascript like:
<script type="text/javascript">
if (<%=rs.Fields(" maa13").Value%> ="true")
{ document.getEle mentById("in100 ").checked=true }
.....

but it seems me possible to do it without scripting, or not?

Thanks
Kevin
Oct 29 '05 #1
4 9796
"Kevin" <ks****@smart.c a> wrote in message
news:OD******** *****@TK2MSFTNG P15.phx.gbl...
Hi,

I have a input with type checkbox. I want it to be automatically checked if the value from the corresponding field in the database is also checked.
I tried this:
<%
set objdc = Server.CreateOb ject("ADODB.Con nection")
etc ...
sql="select maa13 from mytable"
dim rsArray
Set rs = objdc.execute(s ql)
if not rs.eof then
rsArray = rs.GetRows()
rec = UBound(rsArray, 2) + 1
rs.movefirst
...
%>
<html><body>
<input id="in100" name="maa13" type="checkbox"
value="<%=rs.Fi elds("maa13").V alue%>>
....

but nothing happens!
I can do this in Javascript like:
<script type="text/javascript">
if (<%=rs.Fields(" maa13").Value%> ="true")
{ document.getEle mentById("in100 ").checked=true }
....

but it seems me possible to do it without scripting, or not?

Thanks
Kevin


Try:

<% If rs.Fields("maa1 3").Value Then %>
<input id="in100" name="maa13" type="checkbox" value="" checked>
<% Else %>
<input id="in100" name="maa13" type="checkbox" value="">
<% End If %>

Or:

<% Dim strCHK
strCHK = ""
If rs.Fields("maa1 3").Value Then strCHK = "checked"
%>
<input id="in100" name="maa13" type="checkbox" value="" <%=strCHK%>>
Not sure what the value of value= should be.
Oct 29 '05 #2
Kevin wrote:
Hi,

I have a input with type checkbox. I want it to be automatically
checked if the value from the corresponding field in the database is
also checked.
I tried this:
<%
set objdc = Server.CreateOb ject("ADODB.Con nection")
etc ...
sql="select maa13 from mytable"
dim rsArray
Set rs = objdc.execute(s ql)
if not rs.eof then
rsArray = rs.GetRows()
rec = UBound(rsArray, 2) + 1
rs.movefirst
Why did you issue the movefirst? Aren't you planning to close and destroy
the recodset and connection at this point? You should ...
...
%>
<html><body>
<input id="in100" name="maa13" type="checkbox"
value="<%=rs.Fi elds("maa13").V alue%>>
You have an array containing your data. Why are you still using the
recordset?
....

but nothing happens!
Why should it? All you've done is set the value of the the checkbox, ie, the
value that will be contained in the Request if the checkbox is checked. You
haven't set the "checked" property.
I can do this in Javascript like:
<script type="text/javascript">
if (<%=rs.Fields(" maa13").Value%> ="true")
{ document.getEle mentById("in100 ").checked=true }
....
Absolutely. just add the word "checked" into the checkboxes tag if you want
it to be checked (you want to look at the first record in the array,
correct?):

<input id="in100" name="maa13" type="checkbox"
value= "true"
<%if rsArray(0,0) = "true" then "checked" %>


Personally I dislike mixing server-side code in my html. i would prefer:

<%
'same as above, only close and destroy ADO objects after
'creating the array
'Then:

dim sCheckboxHTML
sCheckboxHTML=" <input id=""in100"" name=""maa13"" " & _
"type=""checkbo x"" value = ""true"""
If IsArray(rsArray ) then
'array contains records
if rsArray(0,0) = "true" then
sCheckboxHTML=s CheckboxHTML & " checked"
end if
end if
sCheckboxHTML=s CheckboxHTML & ">"
....
%>
<html><body>
<%=sCheckboxHTM L%>

etc.
HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Oct 29 '05 #3
Thanks both
"Bob Barrows [MVP]" <re******@NOyah oo.SPAMcom> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Kevin wrote:
Hi,

I have a input with type checkbox. I want it to be automatically
checked if the value from the corresponding field in the database is
also checked.
I tried this:
<%
set objdc = Server.CreateOb ject("ADODB.Con nection")
etc ...
sql="select maa13 from mytable"
dim rsArray
Set rs = objdc.execute(s ql)
if not rs.eof then
rsArray = rs.GetRows()
rec = UBound(rsArray, 2) + 1
rs.movefirst
Why did you issue the movefirst? Aren't you planning to close and destroy
the recodset and connection at this point? You should ...
...
%>
<html><body>
<input id="in100" name="maa13" type="checkbox"
value="<%=rs.Fi elds("maa13").V alue%>>


You have an array containing your data. Why are you still using the
recordset?
....

but nothing happens!


Why should it? All you've done is set the value of the the checkbox, ie,

the value that will be contained in the Request if the checkbox is checked. You haven't set the "checked" property.
I can do this in Javascript like:
<script type="text/javascript">
if (<%=rs.Fields(" maa13").Value%> ="true")
{ document.getEle mentById("in100 ").checked=true }
....
Absolutely. just add the word "checked" into the checkboxes tag if you

want it to be checked (you want to look at the first record in the array,
correct?):

<input id="in100" name="maa13" type="checkbox"
value= "true"
<%if rsArray(0,0) = "true" then "checked" %>


Personally I dislike mixing server-side code in my html. i would prefer:

<%
'same as above, only close and destroy ADO objects after
'creating the array
'Then:

dim sCheckboxHTML
sCheckboxHTML=" <input id=""in100"" name=""maa13"" " & _
"type=""checkbo x"" value = ""true"""
If IsArray(rsArray ) then
'array contains records
if rsArray(0,0) = "true" then
sCheckboxHTML=s CheckboxHTML & " checked"
end if
end if
sCheckboxHTML=s CheckboxHTML & ">"
...
%>
<html><body>
<%=sCheckboxHTM L%>

etc.
HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Oct 29 '05 #4
http://www.powerasp.com/content/code...-check-box.asp
"Kevin" <ks****@smart.c a> wrote in message
news:OD******** *****@TK2MSFTNG P15.phx.gbl...
Hi,

I have a input with type checkbox. I want it to be automatically checked
if
the value from the corresponding field in the database is also checked.
I tried this:
<%
set objdc = Server.CreateOb ject("ADODB.Con nection")
etc ...
sql="select maa13 from mytable"
dim rsArray
Set rs = objdc.execute(s ql)
if not rs.eof then
rsArray = rs.GetRows()
rec = UBound(rsArray, 2) + 1
rs.movefirst
...
%>
<html><body>
<input id="in100" name="maa13" type="checkbox"
value="<%=rs.Fi elds("maa13").V alue%>>
....

but nothing happens!
I can do this in Javascript like:
<script type="text/javascript">
if (<%=rs.Fields(" maa13").Value%> ="true")
{ document.getEle mentById("in100 ").checked=true }
....

but it seems me possible to do it without scripting, or not?

Thanks
Kevin

Nov 27 '05 #5

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

Similar topics

4
4629
by: Jack | last post by:
Hi, I have a checkbox the value which goes to a database via a asp page that builds the sql string. In the front end asp page, the checkbox code is written as follows: <i><input type="checkbox" name="chk_Complete" value="<%Response.Write l_IsChecked%>"<%if cbool(l_IsChecked) then Response.Write " checked"%>> The code to captures the checkbox value in the asp page that builds the sql string is follows
2
6566
by: Asha | last post by:
greetings, i'm loading a datagrid and my gird has checkbox, i want these checkboxex to be check based on the value from the db? can someone please show me the code for it? thanks
2
1465
by: JIM | last post by:
Hello, I would like to solve the following problem : I've a web site with ex. 5 checkboxes Each checkbox contains the name of a certain task ex. asp:Checkbox 1: Task 1 asp:Checkbox 2: Task 2 ...
1
4114
by: Kevin R | last post by:
This is one of the weirdest problems I have ever run into. I have had to trim down a bunch of code to give a sample that is more easily readable by those who will view this. Here is the problem: I dynamically add an htmlcheckbox to a webform in the pages render and set the checked value to true. When the page loads, if I remove the check from the checkbox and then submit it, in the submit event the checkbox' checked value is still...
2
8496
by: ColliersWNC | last post by:
I know there is probably a simple solution to this, but I haven't figured it out yet or seen it else where. Imagine you had a simple web page that looked like the following: <html> <input name="dgSelect:_ctl0:cbSelect" id="dgSelect__ctl0_cbSelect" type="checkbox" /> </html>
10
5209
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked. I set the AutoPostBack property of the CheckBox in the Header to True & am invoking a sub named 'CheckAllRows' on the CheckedChanged event of this CheckBox. The CheckBox in the Header exists within the HeaderTemplate of a TemplateColumn in the...
11
4316
by: =?Utf-8?B?UGFyYWcgR2Fpa3dhZA==?= | last post by:
Hi All, I have a large recordset to be displayed on a ASP 3.0 page. I am using recordset paging for this. For the next and previous link i am passing href as <a href=<Page URl>?page=<%= iPageCurrent - 1 %for Previous. Now when i display the contents i also add a checkbox (for deletion) to each of the records. Now user should be able to select one or more checkboxes across pages and then should be allow to delete all selections together....
4
4439
by: Charlotte | last post by:
Hi, I have a problem with a ASP-script, can somewone help me ? here is what I've got: mypage.asp : .... code ... <%
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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
10147
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
10091
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
9950
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
6739
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
5381
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
4050
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
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.