473,396 Members | 1,860 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 event executing on "delayed" event

Writing ASP.NET pages, I have a need for client-side functions to prevent going to the server for every small change.

I have a list of server side created checkboxes filled with a lot of information being presented in a form on my site. In a JavaScript setup function, I attach the following event handler (I know syntax is wrong, I just simplified it for purposes within this post):

Expand|Select|Wrap|Line Numbers
  1. <for every checkbox>onchange = function()
  2. {
  3.   document.getElementById("LabelUserName").innerHTML = document.getElementById("LabelUserName").innerHTML + this.id + "...";
  4. }
This is just to test the functionality of the checkboxes and the event handler. Currently, LabelUserName is a span, so I just want to print the ID of the CheckBox in that span every time the checkbox gets changed.

The problem occurs when I do click on the checkbox. The first time, nothing happens. Then, subsequent clicks (anywhere on the page) will load the LabelUserName with the id of the checkbox that was clicked previously.

The "delayed" event handling occurs only on the assigned function, i.e. the checkbox gets changed immediately when you click on it. So, that functionality isn't being delayed.

Anyone hear of this before? Can anyone help?

Thanks,
Billy
Jul 13 '07 #1
8 2313
acoder
16,027 Expert Mod 8TB
Can you give some more code - the generated source code, not .NET.
Jul 16 '07 #2
This is my JavaScript function to setup my client-side operations. The HTML body tag executes Setup() on its onload event.

Expand|Select|Wrap|Line Numbers
  1. function Setup()
  2. {
  3.   var i;
  4.   var elements = document.Form1.elements;
  5.  
  6.   for(i = 0; i < elements.length; i++)
  7.   {
  8.     if(elements[i].id.indexOf("Hidden") > -1)
  9.     {
  10.       //Hide/show division associated with this hidden input
  11.     }
  12.     if(elements[i].id.indexOf("CheckBox") > -1)
  13.     {
  14.       elements[i].onchange = function()
  15.       {
  16.         var ID;
  17.  
  18.         TruckID = this.id.substring(this.id.indexOf("CheckBox") + 8, this.id.length);
  19.         document.getElementById("LabelUserName").innerHTML = document.getElementById("LabelUserName").innerHTML + ID + "...";
  20.  
  21. //      if(document.getElementById("Hidden" + ID))
  22. //      {
  23. //      }
  24. //      else
  25. //      {
  26. //      }
  27.       }
  28.     }
  29.   }
  30. }
So, it goes through every element. There are some hidden fields I use to tell JavaScript which divisions need to be hidden or shown, and whether or not the information within each division has already been loaded. This way, I can prevent postbacks when the information is already available.

Then, for each checkbox I find, I just print the ID.

Let me know if there is anymore I can attempt to explain.

Thanks,
Grorange
Jul 16 '07 #3
acoder
16,027 Expert Mod 8TB
ON line 16, you're declaring a variable ID, but you've not set it and then you use it on lines 19 and 21.
Jul 17 '07 #4
ON line 16, you're declaring a variable ID, but you've not set it and then you use it on lines 19 and 21.
My bad, I didn't clean up my simplified version well enough. TruckID is actually ID.

I know for sure the code works. I've seen it in action. Every time I click on a checkbox (well, after I click after I click on the checkbox...), its ID shows up in the label.

Thanks,
Grorange
Jul 17 '07 #5
acoder
16,027 Expert Mod 8TB
Instead of onchange, use onclick.
Jul 18 '07 #6
Instead of onchange, use onclick.
I thought about that as a solution, but there is a problem because I'm creating these checkboxes in ASP.NET. So, when they create the checkboxes, they add a label (without an ID) and you can click on the label to check the checkbox also. If I were to use onclick, I would only be able to do my operation if they clicked on the checkbox.

Do you know how to handle events for these controls:

<CODE><label for="[ID of element]">[Some text]</label></CODE>

Thanks,
Grorange
Jul 18 '07 #7
Brilliant! I decided to mess around and take your advice and use onclick. Apparently, JavaScript knows how to handle events on the labels used for the checkboxes too.

I have never seen:

<CODE><label for[ID]>[Text]</label></CODE>

and don't understand its underworkings. Anyone have a good explanation?
Jul 18 '07 #8
acoder
16,027 Expert Mod 8TB
I have never seen:

<CODE><label for[ID]>[Text]</label></CODE>

and don't understand its underworkings. Anyone have a good explanation?
See this link. You can click on the label instead of a small box or a small radio button.
Jul 18 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

35
by: Will Stuyvesant | last post by:
Here is a question about list comprehensions . The question is dumb because I can do without ; but I am posing the question because I am curious. This: >>> data = ,,] >>> result = >>> for...
16
by: Dave Opstad | last post by:
In this snippet: d = {'x': 1} value = d.get('x', bigscaryfunction()) the bigscaryfunction is always called, even though 'x' is a valid key. Is there a "short-circuit" version of get that...
1
by: Alex Li | last post by:
Dear js/xmlhttp experts, I spent hours but could not solve this problem and hope someone could give me a clue: a onclick event will invoke a function to do a few things: 1. make a hidden DIV...
3
by: Hodad | last post by:
I would like to adapt, as much as possible, the appearance and color red of the font in this button: <P><CENTER><BUTTON VALUE="SUBMIT"><A...
205
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
4
by: Luke Wu | last post by:
I am just wondering what the following terms usually mean: 1) "Standard C" 2) "K&R C" 3) "ANSI C" I am pretty sure "ANSI C" usually refers to the C89 standard, but what
2
by: Iain King | last post by:
New book on wxPython: http://www.manning.com/books/rappin Release date of this month. Does anyone know if it's out yet / has anyone read it and has an opinion? Iain
5
by: citronelu | last post by:
I made a small wxPython app that retrieves web data; for visual logging I use a TextCtrl widget, and stdout is redirected to it, something like this: class RedirectOutput: def __init__(self,...
2
by: moondaddy | last post by:
I writing a WPF windows app in c# and want to determine if the user has pressed the control key and the 'c' key at the same time similar to the standard windows 'copy' shortcut keys. How would I...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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.