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): - <for every checkbox>onchange = function()
-
{
-
document.getElementById("LabelUserName").innerHTML = document.getElementById("LabelUserName").innerHTML + this.id + "...";
-
}
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
8 2313
Can you give some more code - the generated source code, not .NET.
This is my JavaScript function to setup my client-side operations. The HTML body tag executes Setup() on its onload event. - function Setup()
-
{
-
var i;
-
var elements = document.Form1.elements;
-
-
for(i = 0; i < elements.length; i++)
-
{
-
if(elements[i].id.indexOf("Hidden") > -1)
-
{
-
//Hide/show division associated with this hidden input
-
}
-
if(elements[i].id.indexOf("CheckBox") > -1)
-
{
-
elements[i].onchange = function()
-
{
-
var ID;
-
-
TruckID = this.id.substring(this.id.indexOf("CheckBox") + 8, this.id.length);
-
document.getElementById("LabelUserName").innerHTML = document.getElementById("LabelUserName").innerHTML + ID + "...";
-
-
// if(document.getElementById("Hidden" + ID))
-
// {
-
// }
-
// else
-
// {
-
// }
-
}
-
}
-
}
-
}
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
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.
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
Instead of onchange, use onclick.
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
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?
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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
|
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
|
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
|
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,...
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |