473,399 Members | 2,858 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,399 software developers and data experts.

how to write userdefined callback function

Hi,
i know we can wirte a userdefined callback function..

I had a try for a long time though i feel im near but not able to coin out the exact thing. can any body tell me about a user defined callback function... and a sample on how to write it...


looking forward for a reply..


Thanks in advance for your reply...
Sep 3 '07 #1
6 3152
pbmods
5,821 Expert 4TB
Heya, New Learner.

You may find this article useful.
Sep 3 '07 #2
Heya, New Learner.

You may find this article useful.

thx pbmods... The article was useful...

but my doubt is..

whenever http.onreadystatechange value is changed the assigned function is called...

similarly.. i need to create a userdefined handler for ex:
x = somefunction
like onreadystatechange(which is a browser object) whenever the value of x is changed thn somefunction should be initiated.

Is this Possible..


looking forward for a reply..

Thanks in advance
Sep 4 '07 #3
gits
5,390 Expert Mod 4TB
hi ...

so x is a simple js-variable and you want to react with 'somefunction' when the value of x changes?

but i assume you already know WHERE x changes (in case its your own code)? ... everytime a value is assigned to x you may call 'somefunction' or use a set-function for x instead of a simple assignment ... and in that so called 'setter' you may call whatever you want ...

hope i didn't misunderstood your problem?

another method would be to define a watcher:

Expand|Select|Wrap|Line Numbers
  1. obj.watch(property, callback);
  2.  
and to detach the watcher:

Expand|Select|Wrap|Line Numbers
  1. obj.unwatch(property);
  2.  
kind regards
Sep 4 '07 #4
hi ...

so x is a simple js-variable and you want to react with 'somefunction' when the value of x changes?

but i assume you already know WHERE x changes (in case its your own code)? ... everytime a value is assigned to x you may call 'somefunction' or use a set-function for x instead of a simple assignment ... and in that so called 'setter' you may call whatever you want ...

hope i didn't misunderstood your problem?

another method would be to define a watcher:

Expand|Select|Wrap|Line Numbers
  1. obj.watch(property, callback);
  2.  
and to detach the watcher:

Expand|Select|Wrap|Line Numbers
  1. obj.unwatch(property);
  2.  
kind regards
tnx for the idea...
I have tried out the way u suggested ... it works fine...

But my doubt is...
we write:
Expand|Select|Wrap|Line Numbers
  1. http.onreadystatechange=response;
response is triggered whenever onreadystatechange is chnged from 0 .. 4.

similarly... i write
Expand|Select|Wrap|Line Numbers
  1. function base() {
  2.   this.x=0;
  3. }
  4.  
  5. base = new base()
  6.  
  7. function tst(){
  8.   base.x = callfun;
  9. }
in a html page i have 2 buttons

on a 1st onclick event i say base.x=1// I need callfun to be triggered (coz x has changed)
on a 2nd onclick event i say base.x=2// I need callfun to be triggered (coz x has changed)

Is This possible...?


Looking for ward fir a reply..

Thanks in advance
Sep 4 '07 #5
acoder
16,027 Expert Mod 8TB
Please use CODE tags when posting code, e.g.
[code=javascript]Javascript code goes here[/code.] (remove the dot).
Sep 4 '07 #6
gits
5,390 Expert Mod 4TB
hi ...

have a look at the following example:

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function OBJ() {
  3.     this.x = 0;
  4. }
  5.  
  6. OBJ.prototype.increment_val = function() {
  7.     this.x++;
  8. }
  9.  
  10. var obj = new OBJ;
  11.  
  12. obj.watch('x', function(val, oldval, newval) {alert(newval); return newval;});
  13. </script>
  14.  
  15. <a href="#" onclick="obj.increment_val();">increase obj counter</a>
  16.  
kind regards

ps: note watch will not work with IE ... so the 'setter'-method is probably to be preferred :)
Sep 4 '07 #7

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

Similar topics

4
by: ma740988 | last post by:
// file sltest.h #ifndef SLTEST_H #define SLTEST_H class CallbackBase // herb shutters gotW source .. { public: virtual void operator()() const { }; virtual ~CallbackBase() = 0; };
7
by: Remi Bastide | last post by:
I'm trying to open a blank window and write a message in it. The following page works as expected in IE, but in Firefox the message is not written: <HTML> <HEAD> <TITLE>Document.write...
2
by: Adam | last post by:
This is frustrating me. Opening IE displays the following code fine. When I open a new window the code no longer works. All the HTML is overwritten with the first document.write statement. Tried...
15
by: Felix Kater | last post by:
Hi, in a given library I register callback functions with this function: bool set_callback(int index, int (*callback_function)(long)); I need the callback function to also pass the index...
0
by: Steve - DND | last post by:
We are continually receiving timeout, and "Unable to write data to the transport connection" errors while using the System.Net.HttpWebRequest class from an ASP.Net web page. Below are the two...
3
by: Wen | last post by:
hello, now, i wanna port a c++ program into C# project. a DLL written by C++ and keep it no change, and UI wirtten by C#. my C++ UI code is as below: // error handlers --global function...
11
by: Jia Lu | last post by:
HI all I am making an application with wxpython. But I got a problem when I want to change the display string according to process status. I passed the frame to the processing function and...
0
by: Erwin Moller | last post by:
Hi group, I found something strange in PHP5.2.4 (on IIS7/Vista). I am working on an app that has been running just fine under heavy load for over a year at some custumer of mine. (they have...
2
by: SnehaAgrawal | last post by:
Does anyone know how to call a UserDefined Function written in SQL 2000 from program(I mean I am writing code in VB.net)..I know how to call it from a stored proc. but don't know how to call from my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
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...
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
isladogs
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...

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.