Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 13th, 2012  |  syntax: None  |  size: 1.29 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. I need to access event context AND object context in event handler
  2. function ActivityDialog(_divId, _title) {
  3.  
  4.     function addButton() {
  5.       var buttonElement = document.createElement('input');
  6.       buttonElement.setAttribute('type','button');
  7.       buttonElement.setAttribute('class','button');
  8.       buttonElement.setAttribute('id','updateButton-' + id););
  9.       buttonElement.onclick = this.updateAction;
  10.     };
  11.  
  12.     function updateAction() {
  13.       var buttonId = this.id; // correct: this is the Button
  14.       this.sendUpdateRequest(stringUrl); // not defined: Need to reference the current ActivityDialog!!!    
  15.     };
  16.  
  17.     function sendUpdateRequest(url) {
  18.       // something...
  19.     };
  20.  
  21. }
  22.        
  23. function ActivityDialog(_divId, _title) {
  24.  
  25.     // Store the ActivityDialog context
  26.     var self = this;
  27.  
  28.     function addButton() {
  29.       var buttonElement = document.createElement('input');
  30.       buttonElement.setAttribute('type','button');
  31.       buttonElement.setAttribute('class','button');
  32.       buttonElement.setAttribute('id','updateButton-' + id););
  33.       buttonElement.onclick = this.updateAction;
  34.     };
  35.  
  36.     function updateAction() {
  37.       var buttonId = this.id;
  38.       self.sendUpdateRequest(stringUrl); // <---------------------
  39.     };
  40.  
  41.     function sendUpdateRequest(url) {
  42.       // something...
  43.     };
  44.  
  45. }