3

I have a problem in IE8:

function costructor(sectionId){
$('#nextG').ready(function(){
var counterBis = 0;
slider = '.slider0'+sectionId;
//sliderBox = $(slider).closest('.floatContent');
unitScrollBis = $(slider).find('.floatImg').eq(0).width();
maxImg = $(slider).find('.floatImg').length-2;
    /*problem*/
prev = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id");
next = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id");
    /*END*/
console.log(prev);
console.log(next);
makeMove(counterBis,unitScrollBis,prev,next,slider,maxImg);
function makeMove(counterBis,unitScrollBis,prev,next,slider,maxImg){
if(counterBis <= 0){
    $(prev).fadeOut("fast");
}
else if(counterBis >= maxImg){
    $(next).fadeOut("fast");
}
$(next).click(function(){
    if(counterBis <= maxImg){
        counterBis++;
        $(prev).fadeIn("fast");
        slide(counterBis);
        }
    else{
        $(next).fadeOut("fast");
    }
});
$(prev).click(function(){
    if(counterBis > 0){
        counterBis--;
        $(next).fadeIn("fast");
        slide(counterBis);
    }
    else{
        $(prev).fadeOut("fast");
    }
});
function slide(counterBis){
    $(slider).animate({
    marginLeft: '-' + (unitScrollBis*counterBis) + 'px'
},1000);
};
};

IE8 says that: SCRIPT438: Object doesn't support property or method Can anyone help me? The problem is only in IE8, I don't understand why IE can't build this string. thanks for the help

Sparky
  • 98,165
  • 25
  • 199
  • 285
ghost
  • 45
  • 1
  • 5

1 Answers1

3

You need to declare variables with the var keyword, otherwise older versions of IE will not recognise them and possibly break.

So change

prev = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id");
next = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id");

to

var prev = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id");
var next = "#" + $("#controller0" + sectionId).find(".controller").eq(0).attr("id");

and everything should work as it does in other browsers/IE9

dsgriffin
  • 66,495
  • 17
  • 137
  • 137
  • 1
    thank's problem solved, ie>8 don't have this problem, and the othe browser too.I have a question to you:'why some developers not use the keyword var for some variables?' – ghost Nov 27 '12 at 14:43
  • @user1856813 Yeah sorry I meant to mention it's like an IE8-and-before issue, IE9+ and others are fine without it thankfully. – dsgriffin Nov 27 '12 at 14:46
  • In regard to your question, check out this question and it's answers - http://stackoverflow.com/questions/1470488/difference-between-using-var-and-not-using-var-in-javascript – dsgriffin Nov 27 '12 at 14:48
  • I have a question to you:'why some developers not use the keyword var for some variables?' – ghost Nov 27 '12 at 14:49
  • 1
    @ghost Because unfortunately for the smart developers, someone wrote "w3schools", teaching all the new programmers horrendous coding practices such as global variables, using keywords as variable names, blah blah blah... – Niet the Dark Absol Nov 27 '12 at 14:49
  • @ghost: without the `var` keyword, the variable is a global. See [here](http://stackoverflow.com/questions/1470488/difference-between-using-var-and-not-using-var-in-javascript) – Matt Burland Nov 27 '12 at 14:52
  • @ Kolink can you suggest me a link as an alternative to w3schools, my problem is simple, I am a web developer who unfortunately has very little basis in javascript(programming methodologies)?thanks – ghost Nov 27 '12 at 16:22
  • Quote user1394965: _"...anywhere but w3c"_ ~ The [w3c](http://www.w3.org/) has **absolutely nothing** to do with [W3Schools](http://www.w3schools.com/)! – Sparky Nov 27 '12 at 16:49
  • I know, but you said, _"anywhere but w3c"_... "w3c" is not the name or acronym of w3schools... instead maybe you meant to say, "w3s"? Let's not add to this confusion by referring to the horrific w3schools with the wrong acronym, or any acronym at all. – Sparky Nov 27 '12 at 16:55