I just tried that but get the same (error/failing) result..
"myDynamicVarName1 is not defined".
Do you have any other suggestions?
Thanks!
-Govinda
Below is sample code from w3schools. Note that is no double-quote or single-quote surrounding undefined. I believe undefined is a special property.
Code:
<script type="text/javascript">
var t1="";
var t2;
if (t1==undefined)
{
document.write("t1 is undefined");
}
if (t2==undefined)
{
document.write("t2 is undefined");
}
</script>
sohguanh,
thanks, but I need it for a *dynamic* var.. and that was the hard part for me.
Fang & savvykms,
those work great, thank you!
criterion9,
I was not sure how to implement an array for this problem because I do not know in advance the dynamic number part of the dynamic var. Server-side code generates a list and I need one dynamic var per item in the list... but it is only the client at runtime who will know how many items should go into that array. Maybe you are saying I should just look to see if the item exists in the array.. but I ended up not trying to go that route since the other posts here solved the issue.
To find the total number of items in an array use ArrayVar.length(). Usually that is a much cleaner way to go rather than testing to see if a series of variables exist that all end with a numeric value (especially true if the numbers are sequential).
that makes sense.. but in this case the question would not be how many items are in the array, but IF the dynamic var had been initialized yet. I was not initializing them onLoad.. I was only initializing upon the first time the user clicked an anchor.. so all the vars were un-initialized at first.. I needed a way to test whether the anchor in question had been clicked yet.. (because after they clicked the anchor then from then on the var was initialized.)
I would still favor an array just for ease of reading/editing later. You can still say you have x number of elements you wish to track in that way and check if they are initialized later.
Personally I would initialize them first, especially if you know or can find out how many elements you'll be identifying in this way at or before page load.
I noticed an array could probably be used for this. The question was about dynamicly created variables through eval() statements, rather than arrays. As far as linking a server-side list/array into a client-side script, try generating the script via PHP or another server-side langauge or CGI setup.
Bookmarks