SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Evangelist pompopom's Avatar
    Join Date
    Feb 2004
    Location
    Huldenberg (Belgium)
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Object doesn't support this property or method

    Hi everyone,

    I'm working myself trough the code from the Ajax web application book.

    coming to page 111 I wanted to try the code so far but it gives me
    when I click the submit button:

    "Object doesn't support this property or method."

    can someone point what can trigger such error message?

    this is the code (copied it from the book):
    The debugger points me to line 103 (wich is: self.toggleEnabled(false); )
    Code JavaScript:
    var Login = new function()
    {
     this.ajax = null;
     this.form = null;
     this.promptDiv = null;
     this.dotSpan = null;
     this.button = null;
     this.enabled = true;
     this.dots = '';
     this.promptInterval = null;
     
     this.cleanup = function()
     {
      var self = Login;
      self.form = null;
      self.promptDiv = null;
      self.dotSpan = null;
      self.button = null;
     };
     
     this.init = function()
     {
      var self = Login;
      self.ajax = new Ajax();
      self.form = document.getElementById('loginForm');
      self.promptDiv = document.getElementById('promptDiv');
      self.dotSpan = document.getElementById('dotSpan');
      self.button = document.getElementById('submitButton');
      self.setPrompt('base', 'Enter login ID & Password');
      self.form.LoginId.focus();
      self.toggleEnabled(false);
      self.form.onsubmit = function() {return false;}
      self.clearCookie('userId');
     };
     
     this.clearCookie = function(name)
     {
      var expireDate = new Date(0);
      document.cookie = name + '=; expires=' + expireDate.toGMTString() + '; path=/';
     };
     
     this.setPrompt = function(stat, msg)
     {
      var self = Login;
      var promptDiv = self.promptDiv;
      var msgSpan = document.getElementById('msgSpan');
      var statusClass = '';
      promptDiv.className = stat + 'Prompt'; // 'base' 'proc' 'err'
      if(msgSpan.firstChild)
      {msgSpan.removeChild(msgSpan.firstChild);}
      msgSpan.appendChild(document.createTextNode(msg));
     };
     
     this.keyup = function(e)
     {
      var self = Login;
      if(!e)
      {e = window.event;}
      if(e.keyCode != 13)
      {self.evalFormFieldState();}
      else
      {
       if(self.enabled)
       {self.submitData();}
      }
     };
     
     this.evalFormFieldState = function()
     {
      var self = Login;
      if(self.form.LoginId.value.length > 5 && self.form.Pass.value.length > 5)
      {self.toggleEnabled(true);}
      else
      {self.toggleEnabled(false);}
     };
     
     this.toggleEnabled = function(able)
     {
      var self = Login;
      if(able)
      {
       self.button.onclick = self.submitData;
       self.button.disabled = false;
       self.button.className = 'inputButtonActive';
       self.enabled = true;
      }
      else
      {
       self.button.onclick = null;
       self.button.disabled = true;
       self.button.className = 'inputButtonDisabled';
       self.enabled = false;
      }
     };
     
     this.submitData = function()
     {
      var self = Login;
      var postData = '';
      postData = formData2QueryString(self.form);
      self.ajax.doPost('php/applogin.php', postData, self.handleLoginResp);
      self.showStatusPrompt();
      self.toggleEnabled(false);
     };
     
     this.showStatusPrompt = function()
     {
      var self = Login;
      self.dots = '';
      self.setPrompt('proc', 'Processing');
      self.promptInterval = setInterval(self.showStatusDots, 200);
     };
     
     this.showStatusDots = function()
     {
      var self = Login;
      var dotSpan = self.dotSpan;
      self.dots += '.';
      if(self.dots.length > 4)
      {self.dots = '';}
      if(dotSpan.firstChild)
      {dotSpan.removeChild(dotSpan.firstChild);}
      dotSpan.appenChild(document.createTextNode(' ' + self.dots));
     };
     
     this.handleLoginResp = function(str)
     {
      var self = Login;
      var respArr = str.split(',');
      var respType = respArr[0].toLowerCase();
      var respMsg = respArr[1];
      if(respType == 'success')
      {location = respMsg;}
      else
      {self.showErrorPrompt(respMsg);}
     };
     
     this.showErrorPrompt = function(str)
     {
      var self = Login;
      var dotSpan = self.dotSpan;
      clearInterval(self.promptInterval);
      if(dotSpan.firstChild)
      {dotSpan.removeChild(dotSpan.firstChild);}
      self.setPrompt('err', str);
      self.form.LoginId.value = '';
      self.form.Pass.value = '';
      self.form.LoginId.focus();
     };
    };
    document.onkeyup = Login.keyup;
    window.onload = Login.init;
    window.onunload = Login.cleanup;

    any help appreciated...

    thx in advance,
    Koen
    The Path of excess leeds to the tower of wisdom (W. Blake)

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var Login = new function(


    Correct use of new would be var Login = new Function();
    with the function arguments and definitiion passed as strings-

    But you want to create an object, apparently a singleton,
    so you could write var Login = new Object(
    //methods and properties
    )

    A bigger problem is your assigning a variable named self to the object-
    self is a keyword that means this.window,
    it cannot be assigned another global value.

  3. #3
    SitePoint Evangelist pompopom's Avatar
    Join Date
    Feb 2004
    Location
    Huldenberg (Belgium)
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok going to try your suggestion.

    but you know, I copied this code right from the sitepoint's book.

    I assume there are other people out there who have encountered / done the same thing...
    Is this implementation of var self = whatever; so wrong??

    greetz,
    Koen
    The Path of excess leeds to the tower of wisdom (W. Blake)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •