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

Home Posts Topics Members FAQ

checkboxlist and javascript

I have a checkboxlist (chkMyList) which is created from a (name, value)
pair from a database table.

I have a read-only textbox which will be used to hold a total of
all the numerical values of each checkbox that is checked, and this
value will change dynamically via javascript when a box is ticked or unticked.

e.g.
<script language="javas cript">
function GetCost() {
var iTotalCost;
iTotalCost = 0;

if (document.form. chkMyList_0.che cked){
iTotalCost = iTotalCost + 15;}
if (document.form. chkMyList_1.che cked){
iTotalCost = iTotalCost + 18;}

....etc...
document.form.t xtTotalCost.val ue = iTotalCost;
}
</script>

<asp:checkboxli st id="chkMyList" runat="server" />
<asp:textbox id="txtTotalCos t" runat="server" ReadOnly="True" />
...but when I try to add the 'onchange=GetCo st();' to chkMyList in the
Page_Load():

chkMyList.Attri butes.Add("onCh ange", "GetCost(); ")

...it doesn't add it to the individual checkboxes, but rather to the
<table> generated for the checkboxes by the checkboxlist function.

Hence it doesn't work.

Is there any way to add the javascript to each checkbox in the
checkboxlist as they are generated?

Also a better suggestion for the javascript function would be most
appreciated (Ideally I'd like a function that takes in the checkbox
value, rather than having to hardcode a load of 'if' statements etc)

Thanks in advance!
Peter
--

fiddlewidawiddu m
Feb 20 '06 #1
2 5524
Hello Peter,

Would the following javascript work, perhaps:

var text_to_add;
function addValue(text_t o_add) {
document.getEle mentById("the_t extbox_id").val ue =
document.getEle mentById("the_t extbox_id").val ue + text_to_add;
}

This just adds the value of the textbox to the new value. You would
just call the function in the checkbox onclick() event.

Chris S.
Implied By Design LLC.
http://www.impliedbydesign.com
Free Web Design Tools
http://www.impliedbydesign.com/free-...e-scripts.html

Feb 21 '06 #2
On Mon, 20 Feb 2006 go****@impliedb ydesign.com <google@implied bydesign.
Hello Peter,

Would the following javascript work, perhaps:

var text_to_add;
function addValue(text_t o_add) {
document.getEle mentById("the_t extbox_id").val ue =
document.getEle mentById("the_t extbox_id").val ue + text_to_add;
}

This just adds the value of the textbox to the new value. You would
just call the function in the checkbox onclick() event.


Thanks! I'll give it a shot first thing in the morning.. any idea how I
could attach the 'onclick' to each checkbox as the checkboxlist is
generated?

Peter
--

fiddlewidawiddu m
Feb 21 '06 #3

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

Similar topics

2
13709
by: Satheesh Babu B | last post by:
hai.. am having a checkboxlist..now how do i get the value of the checkbox that is checked in checkboxlist using javascript? Thanks in advance.... Regards, Satheesh
0
7949
by: Bryce Budd | last post by:
Hello All, I've been a taker of information from newsgroups for a long time and thought I'd finally make a contribution back to the community whose supported me when I've needed it. After all before commercialization took over that was the beauty of the Internet! I've create a checkboxlist validator control...something MS should have done originally in my opinion, but nonetheless here it is. It's a C# control, sort of IE specific. ...
3
5456
by: Robin Day | last post by:
I run some code on the changed event of checkbox lists. Its quite simple, nothing more than showing / hiding some other parts of the page. Using Autopostback and Server side code works fine, but is far too slow, especially if the users are on modems. I need to quite simply, add some java code to the onclick event of the input tags of a checkboxlist. However... Attributes.Add adds the onclick attribute and code to the outlying table that...
10
1963
by: suzy | last post by:
i have generated a list of checkboxes (at runtime) using the checkboxlist control. i want to add an onclick event onto each checkbox so i can perform a count of how many items have been selected every time a checkbox is clicked. how can i do this? remember, the checkboxes are generated at runtime. thanks
1
1835
by: Ryan Scully | last post by:
Hello I have problem with determining exactly what CheckBoxList element is selected using JavaScript code. When I databind to the checkboxlist it renders it on the page and instead of giving each checkbox a value, it gives it a name and does a <label> tag for the Text of the item, and has nothing about the value anywhere in the rendered code for the checkboxlist. So when I enumerate through the controls on the page in javascript, I can never...
7
2228
by: ThunderMusic | last post by:
Hi, I have a CheckBoxList and I want to add some javascript code to each CheckBox created by this CheckBoxList. I tried iterating through all items of the list, all the controls, do a FindControl, et al. with no good result. I would use the Control.Attribute.Add("OnClick", "some javascript code") Does someone know a solution? Thanks
2
6255
by: Bart Van Hemelen | last post by:
The situation: I have a CheckBoxList cblTest, the items are disabled in cblTest_DataBound in a foreach (ListItem oItem in cblTest.Items) loop. I provide a link that calls a client-side JavaScript that enables the items -- this works perfectly. However, when I then click a LinkButton that does a postback and I loop through the items on serverside to pick up the selected ones, it doesn't pick them up. IMHO it seems to loop though the items...
4
22850
by: haresh.amis | last post by:
hello to all, I m using .net 2.0 and i face a problem that is as under Well I have a checkboxlist which i bound in .cs page now I want to count that how many checkboxes ate checked ( In javascript ) and checked checkboxes text will be concat and that string will be pass on to report query I m trying on by this code but it's not work
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
10329
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10092
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
8974
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6740
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
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.