user656925
user656925

Reputation:

IE8 | Not an object error

On IE8 (not on IE9 or Safari) I get an error

this.text_array is null or not an object

for this line

`if( this.text_array[element].value === '' )` 

for this object -

/**
 *          JClass - Text
 */

var Text = function( form_name ) 
{
    this.text_array = document.forms[form_name].elements;
};

Text.prototype.patterns = 
{
    prefix_url:     /^(http:)|(https:)\/\//,
    url:            /^.{1,2048}$/,
    tweet:          /^.{1,40}$/, 
    title:          /^.{1,32}$/, 
    name:           /^.{1,64}$/, 
    email:          /^.{1,64}@.{1,255}$/,
    pass:           /^.{6,20}$/
};

Text.prototype.checkPattern = function( type ) 
{
    return this.patterns[type].exec( this.text_array[type].value );
};

Text.prototype.checkUrlAdd = function( type ) 
{
    return this.patterns[type].exec( this.text_array.url.value );
};  

Text.prototype.checkSameEmail = function() 
{
    return ( (this.text_array.email.value) === (this.text_array.email1.value) );
};

Text.prototype.checkEmpty = function() 
{
    var element;
    for ( element in this.text_array )
    {
        if( this.text_array[element].value === '' ) 
        {
            return 0;
        }
    }
    return 1;
};

Not sure where to begin troubleshooting this. I guess I could start by hard coding the element object...that would eliminate the DOM Pull as a suspect. I could continue in this way...but I don't have IE8 available right now. Trial and Error unless someone has a bit of insight.

Related SO

for in vs. for

Upvotes: 3

Views: 287

Answers (2)

user656925
user656925

Reputation:

Ended up using

document.getElementById()

for form access as a quick solution to fix the problem. Did not have time to troubleshoot further per suggestions.

Upvotes: 1

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324810

To start your debugging, use console.log(this.text_array); in relevant places.

I can only assume it's caused by this not being set right by the browser. In this case, start your checkEmpty function with var that = this; and use that instead of this through it.

Upvotes: 1

Related Questions