/    Sign up×
Community /Pin to ProfileBookmark

rookie to js, cant get a variable working

hi,

new to the forum, I am trying to get an alert to show all of the items defined by “G_items” I am using this code

when I do

[CODE]alert(G_items);[/CODE]

it works fine, but when I add a variable saying

[CODE]var id = g_items;[/CODE]

then in the alert say

[CODE]alert(id);[/CODE]

it just gives me undefined :S can anyone help

Simon

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@FangNov 13.2009 — What is G_items and g_items? They are different variables.
Copy linkTweet thisAlerts:
@simonstatonauthorNov 13.2009 — the first G_items was a type because I didnt copy the code just typed it in they are both without capitals in the actual code. and they are objects
Copy linkTweet thisAlerts:
@FangNov 13.2009 — What is g_items?
Copy linkTweet thisAlerts:
@jamesbcox1980Nov 13.2009 — There is nothing wrong with setting one variable to another. Your problem most likely lies in setting g_items. Can you provide us with the entire JS file? Also, please remember that copying/pasting code is the best way to do post here, because your error could rely in spelling or syntax, which might be an error you might not make typing it directly here. (in other words, you might not make the same error twice)
Copy linkTweet thisAlerts:
@ChadAyersNov 14.2009 — From what I'm understanding form your message is that your looking to have a JavaScript Array and then have all the array items displayed as an alert? If this is what you are looking for, I just wrote an article on my website with details:

http://chadscode.com/index.php/Alert_JavaScript_Array
×

Success!

Help @simonstaton 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.20,
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,
)...