0

essentially i have this div

<div id="trafficcam" style="text-align:center;display:none;">
<img id="image" src="http://131940.qld.gov.au/DMR.Controls/WebCams/DisplayImage.ashx?FilePath=Gold_Coast/GrandisSth.jpg" alt="Sorry, no traffic cam is available">

and I'd like to change the src of the file so that when a button is pressed the image changes. I can't really hide it and have it show a different one because this div is for the traffic cams, and i'd rather have it a bit more compact.

the button to execute it is

<input type=button  value="cam" onclick="selectCam()">

which i have tested and it works

the function it calls is:

      function selectCam()
{
alert(document.getElementById("image"))
             document.getElementbyId("image").src="http://i.imgur.com/zP9kTfe.jpg";

         }

which seems to not change anything on the page when the button is pressed

4
  • You forgot a semi colon after the alert. This will stop the js from running Commented May 18, 2013 at 16:09
  • What error do you see in the console? Commented May 18, 2013 at 16:10
  • 1
    @tymeJV No it wouldn't. Why would the semicolon there change anything? Commented May 18, 2013 at 16:11
  • the issue happens with or without the alert, and there is no error. The image just doesn't just change. Commented May 18, 2013 at 16:11

2 Answers 2

2

There is no method getElementbyId, it's called getElementById. Check out the error console, there should be something like

Unhandled Error: 'document.getElementbyId' is not a function
Sign up to request clarification or add additional context in comments.

6 Comments

More generally, JavaScript is case-sensetive.
jfc that was all it was. Thank you. Been working on this for two days ;_;
hey, i've applied your change and it worked in the button, but now it wont work in a drop down menu, any ideas?
pastebin.com/4CGLPgpf this is the full code, I wasn't getting any run time errors. No files are local, just running it in coda.
Had it worked before? I think it's better to use a select's onchange event rather than option's onclick.
|
0

Also watch out for the insidious getElementByID (the "D" shouldn't be capitalised).

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.