CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2007
    Posts
    28

    variable check and modify

    I need a function that will check a variables value and execute a function depending on the value. The value will always be either 0 or 1. If the variable is = to 0, then function 1 executes and changes the variables to 1. if the main function is called again, the second function will execute within it since the varibale is now 1. This will loop as described.

    Heres what I did:

    Code:
    var wwidth = window.getWidth()-20;
    var wheight = window.getHeight()-20;
    var iwidth = window.getWidth()-20;
    var iheight = window.getHeight()-68;
    var tbontb = 0;
    function maxchecker() {
    if (tbontb == 0) {
    function maxit() {
    document.getElementById("wone").style.width=""+wwidth+"px";
    document.getElementById("wone").style.height=""+wheight+"px";
    document.getElementById("wone").style.top="0px";
    document.getElementById("wone").style.left="0px";
    document.getElementById("inner").style.width=""+iwidth+"px";
    document.getElementById("inner").style.height=""+iheight+"px";
    tbontb=1
    }
    }
    if (tbontb == 1) {
    function maxitback() {
    document.getElementById("wone").style.width="500px";
    document.getElementById("wone").style.height="200px";
    document.getElementById("inner").style.width="498px";
    document.getElementById("inner").style.height="200px";
    tbontb=0
    }
    }
    }
    Wont seem to work at all

    see I need either of the functions I mentioned above (maxit or maxitback) to execute when an "a" element is clicked on in the html body.

    so Id need something like this:
    <a href="..." onmousedown="maxchecker();">..</a>
    so when that element is pressed, either one of the functions is executed depending on the tbontb value

  2. #2
    Join Date
    Jul 2007
    Location
    Sweden
    Posts
    331

    Re: variable check and modify

    You're just creating the functions in your if blocks, not executing them. What you need to do is to create your functions outside the maxchecker() function. Then you make the maxchecker() function something like this:
    Code:
    var tbontb = 0;
    function maxchecker() {
      if (tbontb == 0)
        maxit();
      else if (tbontb == 1)
        maxitback();
    
      // Toggle tbontb
      tbontb = 1 - tbontb;
    }
    Then you run the function on the onclick event of a link:
    Code:
    <a href="#" onclick="maxchecker(); return false;">...</a>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured