473,396 Members | 1,755 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.

checkbox problem

PJ6
OnPreRender if I add this...

Me.Attributes.Add("onmousedown", "alert(this.checked)")

I get 'undefined', at least in IE. Everywhere I look "checked" is supposed
to be the property to retreive the value of a checkbox... obviously I've
missed something. Someone want to give me a clue?

Thanks,
Paul
Jan 13 '06 #1
3 1210
> Everywhere I look "checked" is supposed
to be the property to retreive the value of a checkbox... obviously I've
missed something. Someone want to give me a clue?
'checked' is the correct property, and should work on any version of IE3. It might help if you posted a bit more of the relevant source code [and also check the HTML from 'View Source']. Also, see what 'this' is set to - if it's undefined itself, then IE is probably being silly; you could try something like getElementByID(...) to get a reference to the object. But 'this' should work...


Jan 13 '06 #2
Paul,

Is this a checkbox list or a single checkbox?

If it's a list then you have to specify which item in the list to check.
Another difficulty is the way .NET renders the list using columns. Here's a
script I wrote as part of a CheckBoxList Validator I created:

Dim StringBuilder As New Text.StringBuilder
StringBuilder.Append("<script language=""javascript"">" &
vbCrLf)
StringBuilder.Append("<!--" & vbCrLf)
StringBuilder.Append("function
checkboxlist_verification(clientID) {" & vbCrLf)
StringBuilder.Append("var val =
document.all[document.all[clientID].controltovalidate];" & vbCrLf)
StringBuilder.Append("var col = val.all;" & vbCrLf)
StringBuilder.Append("if (col != null ) {" & vbCrLf)
StringBuilder.Append("var checked = 0;" & vbCrLf)
StringBuilder.Append("var checkboxcount = 0;" & vbCrLf)
StringBuilder.Append("for (i = 0; i < col.length; i++ ) {" &
vbCrLf)
StringBuilder.Append("if (col.item(i).tagName == 'INPUT') {"
& vbCrLf)
StringBuilder.Append("checkboxcount += 1;" & vbCrLf)
StringBuilder.Append("if (col.item(i).checked ) {" & vbCrLf)
StringBuilder.Append("checked += 1;" & vbCrLf)
StringBuilder.Append("if (checked == " &
NumberOfCheckBoxesRequired & ") {" & vbCrLf)
StringBuilder.Append("return true;" & vbCrLf)
StringBuilder.Append("}" & vbCrLf)
StringBuilder.Append("}" & vbCrLf)
StringBuilder.Append("}" & vbCrLf)
StringBuilder.Append("}" & vbCrLf)
StringBuilder.Append("if (checked == checkboxcount) {" &
vbCrLf)
StringBuilder.Append("return true;" & vbCrLf)
StringBuilder.Append("};" & vbCrLf)
StringBuilder.Append("else {" & vbCrLf)
StringBuilder.Append("return false;" & vbCrLf)
StringBuilder.Append("}" & vbCrLf)
StringBuilder.Append("}" & vbCrLf)
StringBuilder.Append("}" & vbCrLf)
StringBuilder.Append("-->" & vbCrLf)
StringBuilder.Append("</script>" & vbCrLf)

ClientScriptManager.RegisterClientScriptBlock(Scri ptType,
"CheckBoxListVerification", StringBuilder.ToString())

The component I created lets you specify how many checkboxes in a
checkboxlist must be checked for the page to validate. If that's what you
happen to be attempting you may download the component which is free and
includes all source code from here:

http://www.aboutfortunate.com/defaul...tvalidatordemo
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"PJ6" <no****@nowhere.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
OnPreRender if I add this...

Me.Attributes.Add("onmousedown", "alert(this.checked)")

I get 'undefined', at least in IE. Everywhere I look "checked" is supposed
to be the property to retreive the value of a checkbox... obviously I've
missed something. Someone want to give me a clue?

Thanks,
Paul

Jan 13 '06 #3
PJ6
I'll be damned but this morning it's working as expected. Yesterday it was
giving me 'undefined'. I have no idea why, probably my fault, something
dumb. Par for the course.

Paul

--------
Public Class TestControl
Inherits CheckBox

Public Sub New()
Me.Text = "1234"
End Sub

Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
Me.Attributes.Add("onclick", "alert(this.checked)")
MyBase.OnPreRender(e)
End Sub

End Class

"PJ6" <no****@nowhere.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
OnPreRender if I add this...

Me.Attributes.Add("onmousedown", "alert(this.checked)")

I get 'undefined', at least in IE. Everywhere I look "checked" is supposed
to be the property to retreive the value of a checkbox... obviously I've
missed something. Someone want to give me a clue?

Thanks,
Paul

Jan 14 '06 #4

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

Similar topics

1
by: Claire | last post by:
Hello, I am having a problem in my struts application with the checkboxes in my form. I have an array of checkboxes, some of which may be already selected when the form loads. My problem is when...
2
by: Tomas Vera | last post by:
Hello All, I'm having problems creating a page with dynamic checkboxes in a WebApp. In my app, I need to query a database, then (based on results) add checkboxes to my form and set their...
0
by: mike | last post by:
Hi there: I've read an excellent "how to"-article by Microsoft (no. 306227) - partly cited cited at the end of this email). I have implemented the code related to the part "How to Add a...
10
by: Jennyfer J Barco | last post by:
Hello, I have a datagrid that brings some information from a query. I need to have a checkbox in each row so the user can select the rows he wants to reprint. Is it possible to have a checkbox...
4
by: SJ | last post by:
Hi all, I have come across a weird problem when attempting to automatically set the focus in a vb.net form to a checkbox control... In my form I have (on a tab page in a tab control) several...
1
by: spolsky | last post by:
try the the following code with Opera 9.01 (Windows). when clicked slightly faster than normal clicking, the toggler checkbox and other checkboxes displays differently although event method works...
9
by: morellik | last post by:
Dear all, I have a program that creates dinamically a web page. In the page I have the following function to check how many checkbox are checked. function tarInfo(info) { var i=0; var c=0;...
0
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
3
by: Mahathi | last post by:
Hi I have a small problem in maintaining the state of a check box. Please do me a favour by telling me the procedure how to do that. My requirement is that "I have to map some roles with...
4
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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.