0

I have a rotating slide show I'm working on that uses Javascript. I use a counter in the function, and I want to display the value of the counter each time the image changes. (so it will say "viewing i of x pictures")

I tried using

<script language="javascript" type="text/javascript">document.write(i);</script>

but it only displays the value of i when the page loads, and it won't update each time i increases. Is there something better than document.write(i) that will update each time i increases or decreases?

Ben
  • 1,023
  • 7
  • 18
  • 35
  • 1
    possible duplicate of [What is the correct way to write HTML using Javascript?](http://stackoverflow.com/questions/1533568/what-is-the-correct-way-to-write-html-using-javascript) And apart from using DOM methods, as specified in the answers of the linked question, the `language` attribute of the `script` element has been [deprecated](http://www.w3.org/TR/REC-html40/interact/scripts.html#edef-SCRIPT). – Marcel Korpel Aug 20 '10 at 16:38

2 Answers2

4

In your HTML, instead of the above SCRIPT tag have something like this:

<div id="counter"></div>

In your Javascript function where the counter value updates, have the following line:

document.getElementById('counter').innerHTML = i;
donohoe
  • 13,867
  • 4
  • 37
  • 59
2

wrap the value in a div or span or something similar and include an id attribute. When the image changes, increment i and update the document.getElementById('dividhere').innerHTML with i

CrayonViolent
  • 32,111
  • 5
  • 56
  • 79