/    Sign up×
Community /Pin to ProfileBookmark

Function/varible/object trouble

Dear Sir/Madam,

I’m trying to create a relative simple function:

function test2(menuname) {
menuname2 = (menuname + ‘_arrow’);
menuname2.src = ‘images/layout/syg_selecter_arrow_on.gif’;
}

I don’t know much about Javascript or programming in general. Though I thought this should work, but it does not. Basically I need to know how to tack on a static variable (i.e. _arrow) on my argument.

When I try to use document.write to see what menuname2 is set to it simply reads [object]_arrow. I’m not sure if this is part of the problem, that the javascript does not really merge these two variables in one “string” but simply considers them separate entities or what. If anyone would please shed some light on how to get this to work properly I would very much appreciate it. (This test function is supposed to be part of a larger one).

Thank you!
Regards,
Steve

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@CharlesDec 08.2004 — I need to know more about just what it is that you are up to.
Copy linkTweet thisAlerts:
@steve123authorDec 08.2004 — Alright.

I'm basically trying to call this function onMouseOver on an image. You hover over the image and then the function is supposed to do 2 things:

1.) Change the visibility of a layer &

2.) Change an image.src on a separate image. Basically an "arrow" in front of the group you've hovered over.

onmouseover='javascript:test(overview_123);'

So basically overview_123 will be used for the <div id="overview_123"> tag to change the layer visibility using CSS and on the "arrow pointer" image I have it classified as "overview_123_arroW". I need to change the .src on this image in the same function.


Is this enough?
Copy linkTweet thisAlerts:
@7studDec 09.2004 — menuname2 = (menuname + '_arrow');

That line is fine(although the parentheses don't do anything): it will add the string '_arrow' to the string in the variable menuname2. But, then you do this:

menuname2.src = ....

menuname2 is a string, and a string does not have a .src property. It looks like what you want to do is get an <img> tag and change its source to menuname2, which would look something like this:

document.getElementById("img_id").src = menuname2;
×

Success!

Help @steve123 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

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