/    Sign up×
Community /Pin to ProfileBookmark

What to use in this case as the separator ?

How can I pass a parameter into the function when I’m building the string linke this ?

[CODE] var tempcontainer=galleryarray[i][3]!=””? ” : “”
tempcontainer+='<img onclick=”ChnageImageSource();” style=”cursor:pointer;cursor:hand;” src=”‘+galleryarray[i][0]+'” border=”1″>’
tempcontainer=galleryarray[i][3]!=””? tempcontainer+'</a>’ : tempcontainer
tempcontainer=galleryarray[i][2]!=””? tempcontainer+'<br />’+galleryarray[i][2] : tempcontainer[/CODE]

What I need to do is pass the URL ( galleryarray[i][0] ) into the ChnageImageSource function that looks like this:

[CODE] function ChnageImageSource(FullImageURL) {
var obj = document.getElementById(“imgFULL”);
obj.src=FullImageURL;
return;
}[/CODE]

The problem is that whenever I enclose the galleryarray[i][0] which holds the URL into ‘ or ” I get an error since both is used to create the tempcontainer string. Is there some workaround ?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisFeb 12.2007 — You can get JS to accept the delimiter as a literal character by escaping it with "".
Copy linkTweet thisAlerts:
@vpekulasauthorFeb 12.2007 — I've tried but didn't work.

I've used everything I could think of and the ChnageImageSource() still didn't accept it since it broke the tempcontainer string.
Copy linkTweet thisAlerts:
@UltimaterFeb 12.2007 — One:
<i>
</i>tempcontainer+='&lt;img onclick="ChnageImageSource(&amp;quot;'+galleryarray[i][0]+'&amp;quot;);" style="cursor:pointer;cursor:hand;" src="'+galleryarray[i][0]+'" border="1"&gt;'

Two:
<i>
</i>tempcontainer+='&lt;img onclick="ChnageImageSource(''+galleryarray[i][0]+'');" style="cursor:pointer;cursor:hand;" src="'+galleryarray[i][0]+'" border="1"&gt;'

Three:
<i>
</i>tempcontainer+='&lt;img onclick="ChnageImageSource('+"'"+galleryarray[i][0]+"'"+');" style="cursor:pointer;cursor:hand;" src="'+galleryarray[i][0]+'" border="1"&gt;'

Four:
<i>
</i>tempcontainer+='&lt;img onclick="ChnageImageSource(this.src);" style="cursor:pointer;cursor:hand;" src="'+galleryarray[i][0]+'" border="1"&gt;'

Five:
<i>
</i>tempcontainer+='&lt;img onclick="ChnageImageSource(this);" style="cursor:pointer;cursor:hand;" src="'+galleryarray[i][0]+'" border="1"&gt;'
function ChnageImageSource(t) {
var FullImageURL=t.getAttribute("src");
var obj = document.getElementById("imgFULL");
obj.src=FullImageURL;
return;
}

Although the code will work without it, you might want to also rename your function, and all calls to it, from Ch[color=red]na[/color]geImageSource to ChangeImageSource so it uses proper English spelling.
Copy linkTweet thisAlerts:
@vpekulasauthorFeb 12.2007 — You are the man! Thanks, much appreciated - I love learning new stuff.
×

Success!

Help @vpekulas 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.18,
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,
)...