3

I'm running the JavaScript below to place horizontal scrolling text on the banner of my website. It works in one server but not another. I get the following error:

Error: 'this.mqo' is null or not an object

JavaScript:

function start() {
    new mq('m1');
/* new mq('m2');
    */
    mqRotate(mqr); // must come last
}
window.onload = start;

// Continuous Text Marquee
// permission to use this Javascript on your web page is granted
// provided that all of the code below in this script (including these
// comments) is used without any alteration

function objWidth(obj) {
    if (obj.offsetWidth) return obj.offsetWidth;
    if (obj.clip) return obj.clip.width;
    return 0;
}
var mqr = [];

function mq(id) {
    this.mqo = document.getElementById(id);
    var wid = objWidth(this.mqo.getElementsByTagName('span')[0]) + 5;
    var fulwid = objWidth(this.mqo);
    var txt = this.mqo.getElementsByTagName('span')[0].innerHTML;
    this.mqo.innerHTML = '';
    var heit = this.mqo.style.height;
    this.mqo.onmouseout = function () {
        mqRotate(mqr);
    };
    this.mqo.onmouseover = function () {
        clearTimeout(mqr[0].TO);
    };
    this.mqo.ary = [];
    var maxw = Math.ceil(fulwid / wid) + 1;
    for (var i = 0; i < maxw; i++) {
        this.mqo.ary[i] = document.createElement('div');
        this.mqo.ary[i].innerHTML = txt;
        this.mqo.ary[i].style.position = 'absolute';
        this.mqo.ary[i].style.left = (wid * i) + 'px';
        this.mqo.ary[i].style.width = wid + 'px';
        this.mqo.ary[i].style.height = heit;
        this.mqo.appendChild(this.mqo.ary[i]);
    }
    mqr.push(this.mqo);
}
function mqRotate(mqr) {
    if (!mqr) return;
    for (var j = mqr.length - 1; j > -1; j--) {
        maxa = mqr[j].ary.length;
        for (var i = 0; i < maxa; i++) {
            var x = mqr[j].ary[i].style;
            x.left = (parseInt(x.left, 10) - 1) + 'px';
        }
        var y = mqr[j].ary[0].style;
        if (parseInt(y.left, 10) + parseInt(y.width, 10) < 0) {
            var z = mqr[j].ary.shift();
            z.style.left = (parseInt(z.style.left) + parseInt(z.style.width) * maxa) + 'px';
            mqr[j].ary.push(z);
        }
    }
    mqr[0].TO = setTimeout('mqRotate(mqr)', 10);
}
1
  • Please don't post minified code, it's a nightmare to read. I used jsbeautifier.org to clean up your post. Commented Sep 28, 2010 at 8:26

1 Answer 1

4

The reason is most likely that there is no element with the id "m1". Place this line first in the start function to diagnose this:

alert(document.getElementById('m1'));

If it shows "[Object]" (or similar), the element exists and it's some other problem, but if it shows "undefined" it means that there is no such element in the page.

Sign up to request clarification or add additional context in comments.

11 Comments

@GM2: is it possible your HTML markup is different on each server?
@GM2: Because there is something on the servers that causes something in the HTML code to be different. The client script has nothing to do with the server, so the difference has to be evident in the page that runs in the browser.
I placed the alert within the function and it's prompting a "null" on page load.
@GM2: That's right... The method returns null instead of undefined. It means that there is no element with the id "m1" in the page. View the page source in the browser, locate the element that you want to use, and check what it's actual id is.
YEs, there is an div id with "m1". here's the line of code in the template file. <ItemTemplate> <div id="m1" class="marquee"><span><%# Eval("Test_Text") %></span></div> </ItemTemplate>
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.