Hi all,
I'm looking for a way to "bind" multiple eventhandler function to the same
event. In other languages this can often be done by using the += operator,
unfortunately this doesn't seem to work.
My (working) code for assigning an eventhandler for some form elements is:
for( var i = 0; i < document.formx. elements.length ; i++ ) {
document.formx. elements[i].readonly = true;
alert( document.formx. elements[i].onclick );
document.formx. elements[i].onclick = HandlerFunction X;
}
Is this possible? And if so, how should it be accomplished?
Thanks in advance,
Jan-Willem 2 1601
On 18 May 2004 05:50:55 -0700, JeeWee wrote: I'm looking for a way to "bind" multiple eventhandler function to the same event. In other languages this can often be done by using the += operator,
In C#, uh?
unfortunately this doesn't seem to work.
You can use addEventListene r method (for browsers DOM W3C compliant), and
attachEvent for IE.
Or simply:
object.onclick= function(){
f1();
f2();
f3();
}
--
C'ya,
ZER0 :: coder.gfxer.web Designer();
...ma in effetti il concetto di WYSYWYG (quello che vedi e' quello che
ottieni)
si applica ai computer malissimo, cosi' come si applica alle donne...
(The Real Programmer)
Now playing: nothing
JeeWee wrote: Hi all,
I'm looking for a way to "bind" multiple eventhandler function to the same event. In other languages this can often be done by using the += operator, unfortunately this doesn't seem to work.
My (working) code for assigning an eventhandler for some form elements is:
for( var i = 0; i < document.formx. elements.length ; i++ ) { document.formx. elements[i].readonly = true;
The property name is "readOnly", not "readonly".
alert( document.formx. elements[i].onclick ); document.formx. elements[i].onclick = HandlerFunction X; }
Is this possible? And if so, how should it be accomplished?
I solved this a while back because I had the same requirement. Here is the
solution I came up with:
function appendFormEleme ntEvent(formNam e, elementName, elementEvent,
eventHandler) {
var f = document.forms[formName];
if (f && f.elements[elementName]) {
f = f.elements[elementName];
if (f[elementEvent]) {
// there is currently an on... event defined for this
// element; append the event handler javascript to the
// current event handler javascript
f[elementEvent] = new Function(
// take the original event
f[elementEvent]
// convert it to a string; the string looks like:
// "...function... ()...{...[js]...}..."
.toString()
// remove any newline characters or carriage returns
.replace(/[\r\n]/g, '')
// remove any leading or trailing whitespace
.replace(/\s+$|^\s+/g, '')
// turn "function...(). ..{...[js]...}"
// into "function...(). ..{...[js][newline][new js]...}"
// NOTE: THE NEXT LINE IS A SINGLE STATEMENT WHICH WILL
// MOST LIKELY WRAP
.replace(/^function\s*\w+ \s*\(\w*\)\s*\{ \s*(.*)\s*\}$/, '$1\n' +
eventHandler)
);
} else {
// there is currently no on... event defined for this
// element; set the event handler javascript to handle
// the event
f[elementEvent] = new Function(eventH andler);
}
}
} // appendFormEleme ntEvent()
- formName is a string, the name of the form
- elementName is a string, the name of the element
- elementEvent is a string, the name of the event (onclick, onfocus, etc)
- eventHandler is a string, the new Javascript code to be added to the event
you use it as follows:
appendFormEleme ntEvent('myForm ', 'mySelect', 'onchange', 'function1();') ;
appendFormEleme ntEvent('myForm ', 'mySelect', 'onchange',
'alert(this.sel ectedIndex);');
Works in Geck based browsers (Mozilla, Firefox, Camino), Internet Explorer
5.5+, Netscape 4.78 and Opera 7+. You might be able to get it working in Opera
6, I have no idea why it doesn't, most likely the format of the toString()
returned by the currently defined event.
I'm sure there are other browsers it doesn't work in, it might be possible to
massage the regular expression to handle those browsers if it were really
necessary.
Thanks in advance,
Jan-Willem
--
| Grant Wagner <gw*****@agrico reunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available at:
* http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
* http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Catherine Lynn Smith |
last post by:
I'm looking through the client side javascript reference and there's
some mighty useful information in here, but it is not very specific on
'reading' information from event handlers.
In the interest of streamlining my scripting, I was thinking I could
write multi-purpose functions to handle mouseOver and mouseOut events.
Thus far, I am...
|
by: Kiyomi |
last post by:
Hello,
I create a Table1 dynamically at run time, and at the same time, I would
like to create LinkButton controls, also dynamically, and insert them into
each line in my Table1. I would then like that, when clicking the
LinkButton, the user can be navigated to another page, carrying a variable.
I would like to use server.transfer...
|
by: James Radke |
last post by:
Hello,
I have a multithreaded windows NT service application (vb.net 2003) that I
am working on (my first one), which reads a message queue and creates
multiple threads to perform the processing for long running reports. When
the processing is complete it uses crystal reports to load a template file,
populate it, and then export it to a...
|
by: Iced Crow |
last post by:
In C# I know that you can use delegates to assing
multiple addresses of sub and functions to a delegate and
have it fire multiple procedures...
How do I do this in VB? I only know of assigning a
single method to a delegate in VB.NET. I want to use it
as in C#... to fire multiple events.
Thanks in advance!
|
by: Armin |
last post by:
Hello
I have a UserControl with a Click Event.
Is it possible to find out the List of all Delegates/Eventhandlers using the
Event.
I read something about a "getinvocationlist" Methode for Delegates
which can get this back, but couldN#t found out how it works.
| |
by: Kasper Birch Olsen |
last post by:
Hi NG
Im adding a bunch of linkbuttons to a page, in a for loop, but I cant get
the eventhandlers to work.
A simplyfied version of the code looks like this:
for (int i = 0; i<10; i++)
{
Button b = new Button();
|
by: Mark |
last post by:
why doesn't .NET support multiple inheritance?
I think it's so silly!
Cheers,
Mark
|
by: Frankie |
last post by:
It appears that System.Random would provide an acceptable means through
which to generate a unique value used to identify multiple/concurrent
asynchronous tasks.
The usage of the value under consideration here is that it is supplied to
the AsyncOperationManager.CreateOperation(userSuppliedState) method... with
userSuppliedState being, more...
|
by: Michael |
last post by:
It seems that a gridview allows us to delete only a single row at a time.
How to extend this functionality to select multiple rows and delete all of
the selected rows in a single stroke? just like what hotmail web UI is doing
now (having the option of selecting multiple rows (using the checkbox
provided) and perform a set of operations on them)
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |