Results 1 to 7 of 7

Thread: Dynamic graphic

  1. #1
    Join Date
    Feb 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Dynamic graphic

    the blue part gets me an image

    but at the red part i get an error, what i'm making wrong



    <html>
    <script language="javascript" type="text/javascript">
    <!--
    function test()
    {
    document.getElementById('cover').src='http://chart.apis.google.com/chart? &chs=200x125 &chd=t:10,58,95|30,8,63 &cht=lc &chxt=x,y'

    clockID = setTimeout("test()", 1000);
    }
    //-->

    </script>
    <body>
    <a ><img src="test1.jpg" width="128" height="128" id="cover" onmouseover="test()" ><br></a>

    <img src="http://chart.apis.google.com/chart?
    &chs=200x125
    &chd=t:10,58,95|30,8,63
    &cht=lc
    &chxt=x,y
    ">


    </body>
    </html>

  2. #2
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default

    Hey, the below version should be fine, I colored my change blue, just a missing ;.

    Code:
    <html>
    <script language="javascript" type="text/javascript">
    <!--
    function test()
    {
    document.getElementById('cover').src='http://chart.apis.google.com/chart? &chs=200x125 &chd=t:10,58,95|30,8,63 &cht=lc &chxt=x,y';
    
    clockID = setTimeout("test()", 1000);
    }
    //-->
    
    </script>
    <body>
    <a ><img src="test1.jpg" width="128" height="128" id="cover" onmouseover="test()" ><br></a>
    
    <img src="http://chart.apis.google.com/chart?
    &chs=200x125
    &chd=t:10,58,95|30,8,63
    &cht=lc
    &chxt=x,y
    ">
    
    </body>
    </html>

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by TimFA View Post
    Hey, the below version should be fine, I colored my change blue, just a missing ;
    I hope I am wrong, but I seriously doubt that would make any difference. Did you test your theory TimFA?

    Anyways, if that doesn't solve the problem:

    Please post a link to the page on your site that contains the problematic code so we can check it out.


    However, this seems to work out:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    
    function test(){
    document.getElementById('cover').src=document.getElementById('chart').src;
    var clockID = setTimeout("test()", 1000);
    }
    
    </script>
    <body>
    <a ><img src="test1.jpg" width="128" height="128" id="cover" onmouseover="test();" ><br></a>
    
    <img style="display:none;" id="chart" src="http://chart.apis.google.com/chart?
    &chs=200x125
    &chd=t:10,58,95|30,8,63
    &cht=lc
    &chxt=x,y
    ">
    
    </body>
    </html>
    But no updating occurs. For that, I think that the &chd=t:10,58,95|30,8,63 would need to be changed each time, though I cannot be sure of that at this point.

    Edit: This part seems unnecessary to me:

    var clockID = setTimeout("test()", 1000);
    Last edited by jscheuer1; 02-17-2008 at 04:52 AM. Reason: add info
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I've looked into this a bit more. The main problem with the original is the spaces:

    document.getElementById('cover').src='http://chart.apis.google.com/chart? &chs=200x125 &chd=t:10,58,95|30,8,63 &cht=lc&chxt=x,y'

    should be:

    document.getElementById('cover').src='http://chart.apis.google.com/chart?chs=200x125&chd=t:10,58,95|30,8,63&cht=lc&chxt=x,y'

    Note: no & is required immediately after the ?, but it can be used. The & character is for separating additional query values. The string of query values begins with a single ? character.
    Last edited by jscheuer1; 02-17-2008 at 07:58 AM. Reason: clarity
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default

    I tried it, I got no error. I didn't even see what it was meant to do so I didn't know if it worked or not...I was in a hurry saw a missing ; and assumed ti was the problem, tested got no error so clearly I thought that fixed it.

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by TimFA View Post
    I tried it, I got no error. I didn't even see what it was meant to do so I didn't know if it worked or not...I was in a hurry saw a missing ; and assumed ti was the problem, tested got no error so clearly I thought that fixed it.
    Though adding a semicolon where there is already a line-break only sometimes changes the meaning of javascript, if that line-break is meant to be interpreted as an understood semi-colon and the script parser doesn't understand it as such, only then will its being omitted cause an execution error. However, many strict script debugging tools may pick up on the missing semi-colon even when it is not required.

    Lots of code that gives no error does nothing, ex:

    Code:
    var p='bob';
    p=null;
    With or without the semicolons, it will set p to null, but essentially does nothing in either case.

    To alin19:

    See my solution in post#4 of this thread.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default

    I understand. I just didn't realize that it wasn't doing what it was supposed to, sometimes I start things and just take sections of broken code to ask for help, so I could see that part there not doing anything. As I said I didn't really look at what it did, so much as syntax.

Bookmarks

Posting Permissions

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