1

I am writing an Open University project that requires me to use Cordova to generate an Android app. To do this, I am using a combination of HTML and JavaScript.

My HTML uses

<div data-role="page" id="view">

etc. to define individual pages within the single HTML file. When the page first runs, it shows a "corporate" logo. After signing in, it shows the personal logo. The url to the logo comes from a database and is held in a JS global variable railroadLogoPath. I have an HTML placeholder Once I move to another page, I can't see how to get the HTML to use the JS to get the url of this logo.

My HTML looks like this:

<img class="banner" id = "signedInlogo"  width = "100%"> 

I have a JS function in index.js as follows:

function insertLogo(anID) {

document.getElementById("anID").src = railroadLogoPath;
}

How do I call this from HTML. I have tried putting it in

<script> insertLogo("signedInLogo")</script> 

but this doesn't work.

I am just starting to understand JS so any help would be appreciated. David

1
  • change this line document.getElementById("anID").src = railroadLogoPath; to document.getElementById(anID).src = railroadLogoPath; Commented Aug 10, 2017 at 14:34

1 Answer 1

1

In this line:

document.getElementById("anID").src = railroadLogoPath;

You're looking for an element by ID with the literal string "anID". You should be using the variable anID

function insertLogo(anID) {
    document.getElementById(anID).src = railroadLogoPath;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.