/    Sign up×
Community /Pin to ProfileBookmark

Inserting an image

hi there, im trying to add an image where Home is, can someone tell me if this is possible with this code?

[code] if (document.getElementById(“surfbarmenu”) != null) {
document.getElementById(“surfbarmenu”).innerHTML = ‘<a target=_top style=”text-decoration:none;color:”.$menuItems.”” href=”members.php” onclick=”userClicked();”>Home</a> | <a target=_blank style=”text-decoration:none;color:”.$menuItems.”” href=”‘ + opensiteurl + ‘”>Open Site</a> | <a target=_blank style=”text-decoration:none;color:”.$menuItems.”” href=”reportsite.php”>Report Site</a> | <a target=_top style=”text-decoration:none;color:”.$menuItems.”” href=”surfbar_settings.php” onclick=”userClicked();”>Surf Settings</a>’;[/code]

Thank you 🙂
Elaine
Edited by site staff: Inserted code tags.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumMay 18.2019 — Hi Elaine,

please use code tags when posting code:

https://www.bbcode.org/examples/?id=15

Obviously you are mixing up Javascript and PHP here. This:
style="text-decoration:none;color:".$menuItems."" href=
is PHP syntax. Note that Javascript runs on the client or the user's browser while PHP is executed on the server. And on the client you cannot access PHP variables.

However you can insert PHP variables into the javascript code like this:
style="text-decoration:none;color:" + &lt;?php echo $menuItems; ?&gt; + "" href=This way the variable is inserted on the sever into the javascript code. Note that this is not possible when the JS code is located in an external JS file.
Copy linkTweet thisAlerts:
@SempervivumMay 18.2019 — PS: Reading this:
if (document.getElementById("surfbarmenu") != null)lets me suspect that you are creating the complete JS code by PHP? Please clarify.
Copy linkTweet thisAlerts:
@enemeth46authorMay 19.2019 — It is a php file and javascript within it does not have an external js file

All I need to do is change the Home with an image instead of just text. I'm not very good with all this I look at the code and I research and try and figure it out, usually I can figure it out, but this one I just cannot add the image for some reason, it has been 2 weeks now, I'm going batty! :)

Thanks for any help you can give me!

ps: I tried to hit the insert code button but it wouldn't work for me for some reason! sorry

Elaine
Copy linkTweet thisAlerts:
@SempervivumMay 19.2019 — Try it like this:
if (document.getElementById("surfbarmenu") != null) {
document.getElementById("surfbarmenu").innerHTML = '&lt;a target=_top style="text-decoration:none;color:".$menuItems."" href="members.php" onclick="userClicked();"&gt;Home &lt;img src="" . $yourimgurl . ""&gt;&lt;/a&gt; | &lt;a target=_blank style="text-decoration:none;color:".$menuItems."" href="' + opensiteurl + '"&gt;Open Site&lt;/a&gt; | &lt;a target=_blank style="text-decoration:none;color:".$menuItems."" href="reportsite.php"&gt;Report Site&lt;/a&gt; | &lt;a target=_top style="text-decoration:none;color:".$menuItems."" href="surfbar_settings.php" onclick="userClicked();"&gt;Surf Settings&lt;/a&gt;';

I tried to hit the insert code button but it wouldn't work for me[/quote]
Use BBCode instead of the button:

https://www.bbcode.org/examples/?id=15
×

Success!

Help @enemeth46 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.4,
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,
)...