Hello all,
I hope whoever reads this post has already understood my needs. I want information(or help) about creating custom events. If anyone has enough knowledge about it please share with me and others.
Thanks.
Hello all,
I hope whoever reads this post has already understood my needs. I want information(or help) about creating custom events. If anyone has enough knowledge about it please share with me and others.
Thanks.
Code:var prop = 3; function check() { if(prop != check.old) prop.onchange(); } check.old = prop; window.setInterval(check, 100); prop.onchange = function() { alert("Property change event has been fired! Property is now: " + this); };
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Looks like the event would fire every 100ms once the prop value had changed.
Oh, and:
Error: prop.onchange is not a function
Source File: file://localhost/ . . . /test/prop_h.htm
Line: 11
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
You are, of course, quite right.Code:var prop = 3; var onchange = { 'prop': function() { alert("Property change event has been fired! Property is now: " + this); } }; function check() { if(prop != check.old) { check.old = prop; if(onchange['prop']) onchange['prop'].apply(prop); } } check.old = prop; window.setInterval(check, 100);
Last edited by Twey; 09-16-2006 at 08:12 PM.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Twey,jschuer1: Can you tell me what this code does(of course, I know it demonstrates a custom event) but how to use it?? Thanks.
It sets up a polling function that checks for a condition (a change in the variable prop's value, in this case) every 100ms. When it detects a change it executes a function which, in this case pops up the alert. You could adapt it to check for any condition and to execute anything when that condition is met. Polls do not have to be continuous. Nor must they use such advanced object oriented coding. If you have a look at this post:
http://www.dynamicdrive.com/forums/s...ad.php?t=13003
It gives a more practical example of a poll using a more mundane coding style. It is a poll that only begins when something else is initiated and that can therefore end when its sought for condition is found and acted upon.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
The idea was that in a real-world setting, one could have a list of properties to monitor, and add/remove them dynamically.Nor must they use such advanced object oriented coding.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
I wasn't complaining. I could learn a thing or two from you as regards this type of javascript. I was just saying, for shachi's benefit, that it doesn't have to start out like that when you are first trying to understand the basic concept.Originally Posted by Twey
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
I was just making a note as to why I did it![]()
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
jscheuer1, Twey: I still don't get a thing(may be because if my low experience in javascript) can you give me a little simple example?? I am all![]()
Bookmarks