PDA

View Full Version : Dynamic graphic



alin19
02-14-2008, 01:03 PM
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>

TimFA
02-17-2008, 04:18 AM
Hey, the below version should be fine, I colored my change blue, just a missing ;.



<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>

jscheuer1
02-17-2008, 04:44 AM
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:


<!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.

This part seems unnecessary to me:

var clockID = setTimeout("test()", 1000);

jscheuer1
02-17-2008, 07:49 AM
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.

TimFA
02-17-2008, 05:18 PM
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.

jscheuer1
02-17-2008, 07:25 PM
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:


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 (http://www.dynamicdrive.com/forums/showpost.php?p=130798&postcount=4) of this thread.

TimFA
02-17-2008, 07:34 PM
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.