1

When i click "test" to frame is resized but when i click it again it doesnt resize back to its original size

function dropdownResize(){

var down = 0;

        if(down == 0){
                parent.document.getElementById('frameMain').rows = '84,84,*';
                down = 1;
            }
        else{
                parent.document.getElementById('frameMain').rows = '84,30,*';
                down = 0;
            }


    }

<a onclick="dropdownResize()"> test</a>
Aron Rotteveel
  • 81,193
  • 17
  • 104
  • 128
Dave819
  • 573
  • 3
  • 10
  • 14

3 Answers3

10

It does not work because down is defined within the scope of the function dropdownResize(). When the function is called, down is reset to 0 every time again.

What you should do: (please note that this is a direct answer to your question and you should probably learn more about variable scope in order to prevent global variables as much as possible)

var down = 0;
function dropdownResize(){
        if(down == 0){
                parent.document.getElementById('frameMain').rows = '84,84,*';
                down = 1;
            }
        else{
                parent.document.getElementById('frameMain').rows = '84,30,*';
                down = 0;
            }
    }
Community
  • 1
  • 1
Aron Rotteveel
  • 81,193
  • 17
  • 104
  • 128
  • 1
    I'd mention something about scope collision, if I wasn't lazy. But I am - so this'll be good enough, haha. – Dan Beam Feb 17 '11 at 10:17
2

try:

var down = 0;

function dropdownResize(){

        if(down == 0){
                parent.document.getElementById('frameMain').rows = '84,84,*';
                down = 1;
            }
        else{
                parent.document.getElementById('frameMain').rows = '84,30,*';
                down = 0;
            }


    }
Jamie
  • 67
  • 2
  • I'm curious what .rows 'num,num,*' mean. can you share a sample on jsfiddle – Abhijit Feb 17 '11 at 10:31
  • 1
    @Ab: It's to do with frames, look up `frameset` on google. They are usually considered bad practise now, so it slightly worries me what this guy is doing. – Callum Rogers Feb 17 '11 at 11:01
1

I think down is a local variable and will be set to 0 each time the function is called.

codev70
  • 11
  • 1