Jump to content

variable check and change


Kovo
 Share

Recommended Posts

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

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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...