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 2367 acoder 16,027
Recognized Expert Moderator MVP
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
acoder 16,027
Recognized Expert Moderator MVP
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
acoder 16,027
Recognized Expert Moderator MVP
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?
acoder 16,027
Recognized Expert Moderator MVP
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 d in data:
.... for w in d:
|
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 doesn't evaluate the
second argument if the first is a valid key? For now I'll code around
it, but this behavior surprised me a bit...
|
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 "wait" message visible by changing its
style.display to "block"
2. download the data with XMLHTTP
3. make the hidden DIV message invisible by setting its display to
"none".
|
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
HREF="http://www.familytreedna.com/surname_join.asp?code=Q17978"
STYLE="TEXT-DECORATION: NONE;">
<FONT COLOR="RED" FACE="COPPERPLATE GOTHIC BOLD">Right
Here</FONT></A></BUTTON></CENTER></P>
|
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, objectTxtCtrl):
self.out = objectTxtCtrl
def write(self, string):
self.out.WriteText(string)
|
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 go about this?
Thanks.
--
moondaddy@noemail.noemail
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
| |
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...
|
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...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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...
| |