turbonerd
turbonerd

Reputation: 1306

IE JS compatibility - working in FF?

The following code displays as intended in FireFox, but isn't displaying at all in Internet Explorer (v8).

        // getLimits init
        Frog.API.get('users.getInfo',
        {
            'params': {'id': UWA.Environment.user.id, 'details':'groups' },
            'onSuccess': AssignPoints.getLimit,
            'onError': function(err) { alert(err); }
        });

...

    // work out the user's limit, and how many points they've spent this week
    // use LEAP library if necessary
    AssignPoints.getLimit = function(data) {
        for (var i in data[0].groups) {
            if (data[0].groups[i].name.indexOf("LEAP") != -1) {
                AssignPoints.Limit = data[0].groups[i].name.substr(5,3);
            }
        }
/************** IT'S THIS LINE ONWARDS WHERE THE ALERTS SEEM TO BREAK IN IE */
        if (AssignPoints.Limit == 0) {
            AssignPoints.Specialist = true;
        }
        
        UWA.Data.getJson(AssignPoints.URL + "?cmd=getLimitsAndTotals&Giver_ID=" + AssignPoints.CurrentUser, AssignPoints.getPointsSpent); 
    }
    
    AssignPoints.getPointsSpent = function(data) {
        AssignPoints.SpentWeekly = data.SpentWeekly;
        AssignPoints.SpentTotal = data.SpentTotal;
        
        AssignPoints.displayLimitAndTotals();
    }

    // display data from getLimitAndTotals
    AssignPoints.displayLimitAndTotals = function() {
        var LimitsAndTotalsHTML = '<h2>Points Allocation</h2>';
        
        if (AssignPoints.Specialist == false) {
            LimitsAndTotalsHTML += '<ul><li>Weekly Limit: <strong>' + AssignPoints.Limit + '</strong></li>';
        } else {
            LimitsAndTotalsHTML += '<ul><li>Weekly Limit: <strong>Unlimited</strong></li>';
        }
        
        LimitsAndTotalsHTML += '<li>Spent this week: <strong style="color:#990000;">' + AssignPoints.SpentWeekly + '</strong></li>' + 
            '<li>Spent total: <strong>' + AssignPoints.SpentTotal + '</strong></li></ul>';

        $('div#limits').html(LimitsAndTotalsHTML);
    }

EDIT: CSS & HTML I don't think it's a CSS/HTML issue, as I have the previous version of this script (which I decided to rewrite because it was hideous code and some odd mash-up of procedural and just pure bodging) which displays correctly in IE using exactly the same HTML&CSS.

#total_container
{ overflow: hidden; width: 870px; }

#groups
{ width: 250px; float: left; padding: 10px; }
#right_container
{ width: 580px; float: left; padding: 10px; }

span.check
{ font-size: 10px; color: #666; }
span.err
{ color: red; font-weight: 700; }

#limits, #search_div
{ width: 270px; float:left; padding: 0 10px; }


#groups li, #groups ul
{ list-style-type: none; background: none; margin: 0; padding: 0; }
#groups li a
{ background-color: #999; color: #eee; display: block; margin: 5px 0; border: #666; padding: 8px 2px 8px 10px; width: 243px; }
#groups li a:hover
{ background-color: #990000; }

The HTML is just <div id="limits"></div> and the JS updates it.

// EDIT

SECOND EDIT: ALERTS

I've tried putting random alerts into the code. In IE, in the for (var i in data[0].groups) loop, the alerts work. If I place an alert at any point after that for loop, the alert doesn't appear at all, regardless of whether I use a variable name or a random string such as "test".

In FF, the alerts work regardless of placement within either function.

** // SECOND EDIT **

FireFox, working as intended FireFox, working as intended

Internet Explorer, b0rked Internet Explorer, b0rked

Does anyone know what might be breaking IE?

Thanks in advance.

Upvotes: 2

Views: 115

Answers (1)

turbonerd
turbonerd

Reputation: 1306

OK! I've found the problem.

IE didn't like this segment of code:

    for (var i in data[0].groups) {
        if (data[0].groups[i].name.indexOf("LEAP") != -1) {
            AssignPoints.Limit = data[0].groups[i].name.substr(5,3);
        }
    }

When I've changed that to this format:

        for (var i = 0; i < data[0].groups.length; i++) {
            if (data[0].groups[i].name.substr(0,4) == "LEAP") {
                AssignPoints.Limit = data[0].groups[i].name.substr(5,3);
            }
        }

It works as intended in FF and IE.

Upvotes: 2

Related Questions