473,585 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get checkbox text in javascript?

Kb
Hi all,
I have an asp:checkbox on a form, and i added onclick attribute to it. When
the checkbox is clicked I want to add its text to a textbox. But I can't get
its text. The checkbox is rendered in html separately, followed by the
<label for> tag - that's where the text is. But how to access it?

Any help is appreciated.

Nov 18 '05 #1
1 11711
Ok, this is a total hack, but I'm assuming want to desperately avoid a
postback. You can use script to check if the checkbox is checked, get at the
innertext of the Label with some Javascript and stuff it into the textbox.
Here's a sample that might get you started:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>chbxfr m</title>
<meta name="GENERATOR " content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
<script language=javasc ript>
function elemnts() {
for(i = 0; i < document.all.le ngth; i++){
if (document.all(" chkRed").checke d==true) {
if (document.all(i ).tagName=="LAB EL") {
document.all("T extBox1").value =document.all(i ).innerText
break;
}
}
}
}
</script>
</HEAD>
<body MS_POSITIONING= "FlowLayout ">
<form id="Form1" method="post" runat="server">
<P>
<asp:CheckBox id="chkRed" runat="server"
Text="Red"></asp:CheckBox>&n bsp;</P>
<P>
<asp:TextBox id="TextBox1" runat="server"> </asp:TextBox></P>
<P>
<asp:Button id="Button1" runat="server" Text="OK" ></asp:Button></P>
</form>
</body>
</HTML>
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles MyBase.Load
Button1.Attribu tes.Add("onclic k", "elemnts(); ")
End Sub

Ken
MVP [ASP.NET]
Toronto

"Kb" <kb**@canada.co m> wrote in message
news:ur******** ******@TK2MSFTN GP09.phx.gbl...
Hi all,
I have an asp:checkbox on a form, and i added onclick attribute to it.
When
the checkbox is clicked I want to add its text to a textbox. But I can't
get
its text. The checkbox is rendered in html separately, followed by the
<label for> tag - that's where the text is. But how to access it?

Any help is appreciated.


Nov 18 '05 #2

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

Similar topics

4
7284
by: Steph | last post by:
Hello, Can someone tell me the script to use for having a change on the same page when using checkbox function ? For example, i would to check one condition and display dynamically a button if the condition is checked on the same page. Thanks in advance for your help
9
13389
by: David D. | last post by:
Does the file extension matter when including a JavaScript file in an HTML page? Normally, one would include a JavaScript file in an HTML page using <script src="foo.JS" type="text/javascript"> However, I have found that I can use an alternate file extension, such as <script src="foo.HTML" type="text/javascript"> It works fine with my...
3
3596
by: Jim Bancroft | last post by:
Hi everyone, This is a silly one I'm sure, but I'm having a whale of a time putting some text into my asp checkbox. Here's what I'd like to do: <asp:CheckBox runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "OptionLabel")%> Fields' ID="chkDBFields"/> ....unfortunately, it doesn't work. The DataBinder text is evaluated...
9
8402
by: Erwin Moller | last post by:
Hi, Can anybody comment on this? In comp.lang.php I advised somebody to skip using: <script language="javascript"> and use: <script type="text/javascript"> And mr. Dunlop gave this response:
2
18264
by: AmitKu | last post by:
<script> function CheckChange() { var mycheck = document.getElementById('test'); mycheck.check = true; } </script> <body> <form id="form1" runat="server">
2
3576
by: Navodit | last post by:
Hi I am new to Javascript and am not sure what is the difference between the following two statements: <script type="text/javascript"> ..... </script>
2
1397
by: itsenthil | last post by:
This is my UserControl(ascx) coding, it is not working plz help me to rectify the error.....what is wrong in that one..... <%@ Control Language="vb" AutoEventWireup="false" Codebehind="Usea.ascx.vb" Inherits="HIS.Usea" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> <script language="javascript" type="text/javascript">...
9
4369
by: Steve | last post by:
Hi; I've being going through some legacy code on an old JSP site I have been patching. I noticed that when I save the JSP down to my PC as an HTML file I get this javascript error in IE 6 ( not in the latest Firefox ): "invalid character" The problem traces back to this line of code:
1
1607
by: neilr | last post by:
MSDN lists .text as a propoerty of the asp check obox but can anyone help me to find out how to access it? We have a panel at the top of our list forms that allows the user to select which columns to show from an SQL stored procedure (via business level code). We have succeeded in getting the names of the check boxes and using this to select...
1
34110
by: vivek kapile | last post by:
Title:Dynamically adding table row with a checkbox using JavaScript Author:Vivek Kapile Email:snipped Language:JavaScript Platform:JavaScript in ASP.net Technology:Used in ASP.net Level:Beginner Introduction
0
7908
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...
0
7836
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...
0
8199
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. ...
0
8336
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...
1
7950
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...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5389
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...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1447
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.