Kovo Posted September 18, 2007 Share Posted September 18, 2007 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: 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 Link to comment Share on other sites More sharing options...
justsomeguy Posted September 18, 2007 Share Posted September 18, 2007 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}}If the variable equals one you just define a function, you don't run it. Link to comment Share on other sites More sharing options...
Kovo Posted September 18, 2007 Author Share Posted September 18, 2007 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}}If the variable equals one you just define a function, you don't run it.dont quite understandsee 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 Link to comment Share on other sites More sharing options...
justsomeguy Posted September 18, 2007 Share Posted September 18, 2007 Right. You don't define the functions inside the if statement, all you want to do is execute them. Define them first, then call them in the if statement. Also, if you do this:if (tbontb == 0){maxit();}if (tbontb == 1){maxitback();}It will run the first one if the variable equals 0, and then it will run the second one because it just got set to 1. You need to use an else so that it doesn't execute the second block if it executes the first one. 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) { maxit(); } else { maxitback(); }}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;}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;} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.