Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check if js variable is set

Status
Not open for further replies.

elliottmina

Programmer
Feb 6, 2005
12
0
0
US
What is the best way to check if a variable is set? If it unset, then I can check its length, but I haven't been able to find any functions like empty(), isset(), etc.

TIA
 
here's a rudimentary way:
Code:
<script type="text/javascript">
	if (isset("foo")) {
		alert("yes foo");
	}
	else {
		alert("no foo");
	}

	function isset(sVarName) {
		return window[sVarName] != null;
	}
</script>

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top