views:

22

answers:

1

why doesnt this work?

//I removed the 'for loops' for a second and then the script does something, what wrong with the loops?//

var openWindows= new Array[50]();

function resize(x){

//changed boolean to var var open = false;

 for(var i = 0; i < openWindows.length; i++){
  if(openWindows[i] == x){
   open = true;
   openWindows[i] = "";
  }
 }

 if(open == false){
  for(var i = 0; i < openWindows.length; i++){
   if(openWindows[i] == ""){
    openWindows[i] = x;
    break;
   }
  }

  var t = setTimeout("document.getElementById('" + x + "').style.height='200px'",20);
  var t = setTimeout("document.getElementById('" + x + "').style.height='220px'",40);
  var t = setTimeout("document.getElementById('" + x + "').style.height='240px'",60);
  var t = setTimeout("document.getElementById('" + x + "').style.height='260px'",80);
  var t = setTimeout("document.getElementById('" + x + "').style.height='280px'",100);
  var t = setTimeout("document.getElementById('" + x + "').style.height='300px'",120);
  var t = setTimeout("document.getElementById('" + x + "').style.height='320px'",140);
  var t = setTimeout("document.getElementById('" + x + "').style.height='340px'",160);
  var t = setTimeout("document.getElementById('" + x + "').style.height='360px'",180);
  var t = setTimeout("document.getElementById('" + x + "').style.height='380px'",200);
  var t = setTimeout("document.getElementById('" + x + "').style.height='400px'",220);
  var t = setTimeout("document.getElementById('" + x + "').style.height='420px'",240);
  var t = setTimeout("document.getElementById('" + x + "').style.height='440px'",260);
  var t = setTimeout("document.getElementById('" + x + "').style.height='460px'",280);
  var t = setTimeout("document.getElementById('" + x + "').style.height='480px'",300);
  var t = setTimeout("document.getElementById('" + x + "').style.height='500px'",320);
  var t = setTimeout("document.getElementById('" + x + "').style.height='520px'",340);
  var t = setTimeout("document.getElementById('" + x + "').style.height='540px'",360);
  var t = setTimeout("document.getElementById('" + x + "').style.height='560px'",380);
  var t = setTimeout("document.getElementById('" + x + "').style.height='580px'",400);
 }else{
  var t = setTimeout("document.getElementById('" + x + "').style.height='560px'",40);
  var t = setTimeout("document.getElementById('" + x + "').style.height='540px'",60);
  var t = setTimeout("document.getElementById('" + x + "').style.height='520px'",80);
  var t = setTimeout("document.getElementById('" + x + "').style.height='500px'",100);
  var t = setTimeout("document.getElementById('" + x + "').style.height='480px'",120);
  var t = setTimeout("document.getElementById('" + x + "').style.height='460px'",140);
  var t = setTimeout("document.getElementById('" + x + "').style.height='440px'",160);
  var t = setTimeout("document.getElementById('" + x + "').style.height='420px'",180);
  var t = setTimeout("document.getElementById('" + x + "').style.height='400px'",200);
  var t = setTimeout("document.getElementById('" + x + "').style.height='380px'",220);
  var t = setTimeout("document.getElementById('" + x + "').style.height='360px'",240);
  var t = setTimeout("document.getElementById('" + x + "').style.height='340px'",160);
  var t = setTimeout("document.getElementById('" + x + "').style.height='320px'",260);
  var t = setTimeout("document.getElementById('" + x + "').style.height='300px'",280);
  var t = setTimeout("document.getElementById('" + x + "').style.height='280px'",300);
  var t = setTimeout("document.getElementById('" + x + "').style.height='260px'",320);
  var t = setTimeout("document.getElementById('" + x + "').style.height='240px'",340);
  var t = setTimeout("document.getElementById('" + x + "').style.height='220px'",360);
  var t = setTimeout("document.getElementById('" + x + "').style.height='200px'",380);
  var t = setTimeout("document.getElementById('" + x + "').style.height='180px'",400);
 }
}
+1  A: 

It's not really clear enough what your code is supposed to do, but I can see a few issues.

The first line has a syntax error:

var openWindows= new Array[50]();  // Should be `Array(50)`

Javascript is a dynamically typed language, you do not need to assert types when declaring variables:

 boolean open = false;

 // Should be
 var open = false;

You should only use the var keyword once for each variable declaration. In this case, every time you declare var t = window.setTimeout(...); you're redeclaring the variable. In fact, you don't need the var t = at all.

Also, you can check to see if a window is closed using the .closed property:

if (windowVar.closed == true) { /* ... */ };
Andy E
It's not a like a window window. It's more like a div acting a window. Changed boolean into var, but the script still doesn't work :(
Jay
I removed the 'for loops' for a second and then the script does something, what wrong with the loops?
Jay
@Jay, there doesn't appear to be anything syntactically wrong with the loops.
Andy E
I see the error now. I declared the array in a wrong way :Pvar openstaandeVensters = new Array[100];
Jay