Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

HowTo set a global variable in javascript or jQuery

Avatar of JAaron Anderson
JAaron AndersonFlag for United States of America asked on
JavaScriptHTMLjQuery
4 Comments1 Solution2146 ViewsLast Modified:
hi all, Ive read alot on the web that simply doesnt make sense on this hoping to have a clear simple discussion on how to handle a string and perform comparison against it along the open session...

e.g.
top of page something like setting default state like so:
<script language="javascript">
var globalSessionValue="false";
</script>
... then many MANY lines later a later function changes the value of the string like so:
<script language="javascript">
function whatever(){
if ( getElementbyID("WhateveruserEvent").value ... whatever comparison here <= === ! > 0) {
globalSessionValue="true";
}
</script>
...
so this way later I can perform another simple if/else on the changed state
<script type="text/javascript">
function evaluateRestriction(){ // this has tested to fire On TAB into the field CONFIRMED
var checkState = globalSessionValue.value; 
		if ( globalSessionValue.length > 4) { //false
			document.getElementById("LogicContainer").innerHTML = "<img src='SHOW GOOD PHOTO' />";
		} else { 
			document.getElementById("LogicContainer").innerHTML = ""; // DONT SHOW anything here

		}	
	}
</script>

<div id="LogicContainer">

</div>