JAaron Anderson
asked on
HowTo set a global variable in javascript or jQuery
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("Whateverus erEvent"). value ... whatever comparison here <= === ! > 0) {
globalSessionValue="true";
}
</script>
...
so this way later I can perform another simple if/else on the changed state
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("Whateverus
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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok thx Ill try the boolean operation
var - is global to the scope it is defined at.
To use globalSessionValue as an object you would have to do something like this
Now you can talk about globalSession.value;
<script>
var superGlobal = true; //Visible everywhere
function test()
{
var localGlobal = false; // Global to function test
}
</script>
To use globalSessionValue as an object you would have to do something like this
var globalSessionValue = {
value: false;
}
Now you can talk about globalSession.value;
ASKER
>>What is your thinking here?
I was trying to declare some sort of interface that carries in the DOM or somwehre I can call back to and get the value of a targeted memory thread.
Ive read if you write "var" in front of a primitive variable it sets it "higher" potentially as a global state ?
anyways with ".value" Im simply trying to access the contents of the container and not the memory thread accessor itself. hth