I have the following code but it keeps on giving me this error when it
runs.
 
--- Error: this.alertBox has no properties
 
What would be causing this?  My Code checks out when I call
this.alertBox() from the setup function it works fine but when I try and
put in on an event observer it doesn''t work.
What do you guys think?
 
Thanks,
 
Jon
 
Code Here:
 
 
var Updater = Class.create();
 
Updater.prototype = {
            initialize: function() {
                        var options = Object.extend({
                                    currentItemId: 0,
                                    debug: false
                }, arguments[0] || {});
                this.options = options;
                this.setup();
            },
            setup: function() {
                        validInputs
[''name'',''image'',''headline'',''caption''];
                        validInputs = $A(validInputs);
                        
                        inputs =
document.getElementsByTagName(''input'');
                        inputs = $A(inputs);
                        
                        inputs.each( function(input) {
                                    try {
 
if(validInputs.indexOf(input.id) != -1) {
 
//input.onblur = this.alertBox.bindAsEventListener(this);
 
Event.observe(input.id,''blur'',this.alertBox.bind(this),false);
                                                }
                                    } catch(e) {
                                                alert(e);
                                    }
                        });
            
            },
            alertBox: function() {
                        alert("Hello")
            }
}
********************
********************
This E-mail (and attachments) may contain confidential/privileged information
intended only for the named addressee(s). If you are not an intended recipient,
do not read, copy, disseminate or take any action based on the content of this
E-mail. Please notify the sender by reply E-mail and erase this E-mail from your
system. Your assistance is appreciated. E-mail transmission may not be secure or
error-free. The company is not responsible for any loss/damage arising from any
virus transmitted.
********************
********************
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
It''s a scoping issue.  ''this'' refers to the object in
the current scope,
inside of the inputs.each, ''this'' refers to the element of the
array.
Try doing something like:
 
var realThis = this;
                        inputs.each( function(input) {
                                    try {
 
if(validInputs.indexOf(input.id) != -1) {
 
Event.observe(input,''blur'',realThis.alertBox.bind(realThis),false);
                                                }
                                    } catch(e) {
                                                alert(e);
                                    }
                        });
 
Greg
 
________________________________
From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]
On Behalf Of
Whitcraft, Jon
Sent: Thursday, March 16, 2006 8:56 AM
To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: [Rails-spinoffs] This is driving me crazy!!!
 
I have the following code but it keeps on giving me this error when it
runs.
 
--- Error: this.alertBox has no properties
 
What would be causing this?  My Code checks out when I call
this.alertBox() from the setup function it works fine but when I try and
put in on an event observer it doesn''t work.
What do you guys think?
 
Thanks,
 
Jon
 
Code Here:
 
 
var Updater = Class.create();
 
Updater.prototype = {
            initialize: function() {
                        var options = Object.extend({
                                    currentItemId: 0,
                                    debug: false
                }, arguments[0] || {});
                this.options = options;
                this.setup();
            },
            setup: function() {
                        validInputs
[''name'',''image'',''headline'',''caption''];
                        validInputs = $A(validInputs);
                        
                        inputs =
document.getElementsByTagName(''input'');
                        inputs = $A(inputs);
                        
                        inputs.each( function(input) {
                                    try {
 
if(validInputs.indexOf(input.id) != -1) {
 
//input.onblur = this.alertBox.bindAsEventListener(this);
 
Event.observe(input.id,''blur'',this.alertBox.bind(this),false);
                                                }
                                    } catch(e) {
                                                alert(e);
                                    }
                        });
            
            },
            alertBox: function() {
                        alert("Hello")
            }
}
 
********************
********************
This E-mail (and attachments) may contain confidential/privileged
information intended only for the named addressee(s). If you are not an
intended recipient, do not read, copy, disseminate or take any action
based on the content of this E-mail. Please notify the sender by reply
E-mail and erase this E-mail from your system. Your assistance is
appreciated. E-mail transmission may not be secure or error-free. The
company is not responsible for any loss/damage arising from any virus
transmitted. 
********************
********************
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
You need to bind your inputs.each() iterator to "this"... otherwise
"this" is not the outer object, but the function object of the
iterator...
 
inputs.each( function(input) {
                                    try {
 
if(validInputs.indexOf(input.id) != -1) {
 
//input.onblur = this.alertBox.bindAsEventListener(this);
 
Event.observe(input.id,''blur'',this.alertBox.bind(this),false);
                                                }
                                    } catch(e) {
                                                alert(e);
                                    }
                        }.bind(this));
 
 
________________________________
From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]
On Behalf Of
Whitcraft, Jon
Sent: Thursday, March 16, 2006 9:56 AM
To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: [Rails-spinoffs] This is driving me crazy!!!
 
I have the following code but it keeps on giving me this error when it
runs.
 
--- Error: this.alertBox has no properties
 
What would be causing this?  My Code checks out when I call
this.alertBox() from the setup function it works fine but when I try and
put in on an event observer it doesn''t work.
What do you guys think?
 
Thanks,
 
Jon
 
Code Here:
 
 
var Updater = Class.create();
 
Updater.prototype = {
            initialize: function() {
                        var options = Object.extend({
                                    currentItemId: 0,
                                    debug: false
                }, arguments[0] || {});
                this.options = options;
                this.setup();
            },
            setup: function() {
                        validInputs
[''name'',''image'',''headline'',''caption''];
                        validInputs = $A(validInputs);
                        
                        inputs =
document.getElementsByTagName(''input'');
                        inputs = $A(inputs);
                        
                        inputs.each( function(input) {
                                    try {
 
if(validInputs.indexOf(input.id) != -1) {
 
//input.onblur = this.alertBox.bindAsEventListener(this);
 
Event.observe(input.id,''blur'',this.alertBox.bind(this),false);
                                                }
                                    } catch(e) {
                                                alert(e);
                                    }
                        });
            
            },
            alertBox: function() {
                        alert("Hello")
            }
}
 
********************
********************
This E-mail (and attachments) may contain confidential/privileged
information intended only for the named addressee(s). If you are not an
intended recipient, do not read, copy, disseminate or take any action
based on the content of this E-mail. Please notify the sender by reply
E-mail and erase this E-mail from your system. Your assistance is
appreciated. E-mail transmission may not be secure or error-free. The
company is not responsible for any loss/damage arising from any virus
transmitted. 
********************
********************
The information transmitted in this electronic mail is intended only for the
person or entity to which it is addressed and may contain confidential,
proprietary, and/or privileged material.  Any review, retransmission, 
dissemination or other use of, or taking of any action in reliance upon,
this information by persons or entities other than the intended recipient
is prohibited. If you received this in error, please contact the sender and
delete the material from all computers.
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Thanks Ryan and Greg, but I could not get either of your solutions to
work. I have just gone back to a standard for loop for now.  I will look
into this more when I''m not on such a tight deadline.
 
Thanks for the explanations it really helped.
 
 
  <http://zend.com/zce.php?c=ZEND002524&r=212822110> 
Jon Whitcraft
Indianapolis Motor Speedway
jwhitcraft-1LwPDYEpVrH2eFz/2MeuCQ@public.gmane.org
Phone: (317) 492-8623 :: Fax: (317) 492-6419
 
________________________________
From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]
On Behalf Of Ryan
Gahl
Sent: Thursday, March 16, 2006 11:02 AM
To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: RE: [Rails-spinoffs] This is driving me crazy!!!
 
You need to bind your inputs.each() iterator to "this"... otherwise
"this" is not the outer object, but the function object of the
iterator...
 
inputs.each( function(input) {
                                    try {
 
if(validInputs.indexOf(input.id) != -1) {
 
//input.onblur = this.alertBox.bindAsEventListener(this);
 
Event.observe(input.id,''blur'',this.alertBox.bind(this),false);
                                                }
                                    } catch(e) {
                                                alert(e);
                                    }
                        }.bind(this));
 
 
________________________________
From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]
On Behalf Of
Whitcraft, Jon
Sent: Thursday, March 16, 2006 9:56 AM
To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: [Rails-spinoffs] This is driving me crazy!!!
 
I have the following code but it keeps on giving me this error when it
runs.
 
--- Error: this.alertBox has no properties
 
What would be causing this?  My Code checks out when I call
this.alertBox() from the setup function it works fine but when I try and
put in on an event observer it doesn''t work.
What do you guys think?
 
Thanks,
 
Jon
 
Code Here:
 
 
var Updater = Class.create();
 
Updater.prototype = {
            initialize: function() {
                        var options = Object.extend({
                                    currentItemId: 0,
                                    debug: false
                }, arguments[0] || {});
                this.options = options;
                this.setup();
            },
            setup: function() {
                        validInputs
[''name'',''image'',''headline'',''caption''];
                        validInputs = $A(validInputs);
                        
                        inputs =
document.getElementsByTagName(''input'');
                        inputs = $A(inputs);
                        
                        inputs.each( function(input) {
                                    try {
 
if(validInputs.indexOf(input.id) != -1) {
 
//input.onblur = this.alertBox.bindAsEventListener(this);
 
Event.observe(input.id,''blur'',this.alertBox.bind(this),false);
                                                }
                                    } catch(e) {
                                                alert(e);
                                    }
                        });
            
            },
            alertBox: function() {
                        alert("Hello")
            }
}
 
********************
********************
This E-mail (and attachments) may contain confidential/privileged
information intended only for the named addressee(s). If you are not an
intended recipient, do not read, copy, disseminate or take any action
based on the content of this E-mail. Please notify the sender by reply
E-mail and erase this E-mail from your system. Your assistance is
appreciated. E-mail transmission may not be secure or error-free. The
company is not responsible for any loss/damage arising from any virus
transmitted. 
********************
********************
The information transmitted in this electronic mail is intended only for
the person or entity to which it is addressed and may contain
confidential, proprietary, and/or privileged material.  Any review,
retransmission, dissemination or other use of, or taking of any action
in reliance upon, this information by persons or entities other than the
intended recipient is prohibited. If you received this in error, please
contact the sender and delete the material from all computers.
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs