/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Dynamic Named Variable

Hello I’m trying to assign a value to a Named Variable.
When I know what the id is it works fine:

[CODE]myCal11 = new Calendar({ [COLOR=”DarkGreen”]Goal1Date1[/COLOR]: ‘m/d/Y’ });[/CODE]

But when I want to add a dynamic id it trips out:

[CODE]myCal11 = new Calendar({ [COLOR=”DarkGreen”]element.id[/COLOR]: ‘m/d/Y’ });[/CODE]

Anyway to add a dynamic name to a named variable!

Thank you!!!

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@jeremuauthorDec 23.2008 — I figured it out:

[CODE]eval("myCal11 = new Calendar({ "+el.id+": 'm/d/Y' }");[/CODE]
Copy linkTweet thisAlerts:
@toicontienDec 23.2008 — You might need a slightly different data structure:
[CODE]myCal11 = new Calendar({ [B]id: element.id, dateFormat: 'm/d/Y'[/B] });[/CODE]
Copy linkTweet thisAlerts:
@cooolblueDec 23.2008 — eval could be costly ...you could create blank calendar first then add the key value pair if possible...like this

myCal11 = new Calendar();

myCal11[element.id] = 'm/d/Y' ..

THnk
×

Success!

Help @jeremu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...