CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2008
    Posts
    17

    Question A graphic odometer

    I have the following code which works fine until I try and display graphics.
    Please tell me how I could/should display the odometer in graphics format rather than text.
    I have all the necessary images as .png(0 through 9) in the same folder as the following code. It is just that the text counter displays but not the graphics?
    Code:
    <html>
    <head>
    <script type="text/javascript">
    var c=0;
    var t;
    var timer_is_on=0;
    function GraphicOdo(Nommer)
        {
        d = Nommer.toString();
        for (i=0; i<d.length; i++)
            {
            var image="<IMG SRC=c"+d[i]+".gif>";
    //        alert(image);
            document.getElementById('GraphicCounter').innerHtml=image; 
            }
        }
    
    function timedCount()
    {
    document.getElementById('txt').value=c;
    c=c+1;
    GraphicOdo(c);
    t=setTimeout("timedCount()",1000);
    }
    
    function doTimer()
    {
    if (!timer_is_on)
      {
      timer_is_on=1;
      timedCount();
      }
    }
    </script>
    </head>
    
    <body>
    <form>
    <input type="button" value="Start count!" onclick="doTimer()">
    <input type="text" id="txt" /><br /><br />
    <div id="GraphicCounter">
    <img src="c0.gif" alt="zero"/>
    </div>
    </form>
    </body>
    </html>

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: A graphic odometer

    First off...it's innerHTML not innerHtml.

    Also...your <img> tag is invalid HTML.

    Code:
    <img src="" alt="" />
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Oct 2008
    Posts
    17

    Re: A graphic odometer

    I understand innerHTML instead of innerHtml, thanks.
    If I uncomment the alert after creating image value it displays exactly whats needed.

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: A graphic odometer

    Not seeing your problem. Works for me!

    Your count is off because you increment the variable before calling the GraphicOdo() function.

    Try the following and see what I mean...

    Code:
    var image = '&lt;img src="c' + d[i] + '.gif" alt="" /&gt;';
    document.getElementById('GraphicCounter').innerHTML = image;
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Oct 2008
    Posts
    17

    Re: A graphic odometer

    Have a look at http://www.k9t.za.net/odometer/ for a better idea.

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: A graphic odometer

    And...what's not working?!?!?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Jan 2009
    Posts
    596

    Re: A graphic odometer

    You said you have the images as png files, 0-9, but you are referring to them as c0.gif, c1.gif etc. It might just be that you have the filenames wrong in the code.

  8. #8
    Join Date
    Oct 2008
    Posts
    17

    Re: A graphic odometer

    My mistake. I will be using .png but during development am using what I have, namely .gif

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured