...

View Full Version : How do you use value of variable as variable name?



cartergarth
03-13-2012, 08:33 AM
I have these lines:


var ddArray=['holidayTypes','groupType','group_status'];
for(var x in ddArray) eval(ddArray[x]=0);
alert(holidayTypes);
alert(groupTypes);
alert(group_status);

But it only alerts something like:


object HTMLSelectElement


Please help, thank you.

devnull69
03-13-2012, 08:54 AM
One important rule for posting questions in developer forums: First state (as exactly as possible) what you want to achieve, then show us what you already tried and last but not least give us a description of the problem/error.

Your description is missing the first and third part.

DaveyErwin
03-13-2012, 01:06 PM
I have these lines:



But it only alerts something like:




Please help, thank you.


<html>
<script>
var ddArray=['holidayTypes','groupType','group_status'];
for(i=ddArray.length;i--;) window[ddArray[i]]=0;
alert(holidayTypes);
alert(groupType);
alert(group_status);
</script>
<body >


</body>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum