/    Sign up×
Community /Pin to ProfileBookmark

undefined variable, that shouldn

Hi all,
I’ve made a piece of code:

[CODE] $(‘#reactions’ + i).attr(‘href’, ‘javascript:comments(‘+entry.url+’,’+i+’);’);
[/CODE]

(this is in a for statement). Than I’m trying to assign the, e.g. reactions1 variable, I just made, to a jquery mobile page like this:

[CODE]document.write(
‘<a href=”#” id=”reactions’ + i + ‘” data-role=”button” class=”ui-btn-right”>Reactions</a>’
);[/CODE]

Strange thing is, when I load this in my browser, the JS console gives me an error: “ReferenceError: Undefined variable: i_heart_chaos_ihc_after_dark_independence_day_through_a_bullhornthis_is_what” (the last thing is the value of entry.url)
I don’t get why this is giving me an error in stead of just calling the comments function.
I hope someone here can help me.

Thanks in advance,
Jan Thiemen

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@maurycyJul 02.2012 — You really miss jQuery abilities and that should be done different way

this is your mistake:
[CODE]javascript:comments('+entry.url+','+i+')[/CODE]

when you replace entry.url with String and i with Integer you will get something like:
[CODE]javascript:comments(That_is_some_freaking_string,1)[/CODE]
and problem with that is that this string is treated as variable now, and it's undefined so it should look like that:
[CODE]javascript:comments("'+entry.url+'",'+i+')[/CODE]
×

Success!

Help @janthiemen 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...