...

View Full Version : adding variable to IMG tag



chelentano
05-03-2004, 05:43 AM
I am trying to have all these charts updated by entry into the text field (I know eventually I have to make function and attach it to text field). In the first IMG tag example I am trying to insert variable which would display chart based on IBM ticker symbol. And something is wrong with my syntax. Please help:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Chart Gallery</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
var myVar = "IBM";
</script>
</head>

<body>
<form name="form1" method="post" action="">
<input type="text" name="textfield">
</form>

<img src="http://stockcharts.com/def/servlet/SharpChartv05.ServletDriver?chart=<script language='JavaScript' type='text/JavaScript'>myVar</script>%2Cuu%5Bm%2Ca%5Deaolynay%5Bd20%5D%5Bph.02%2C.20%21f%5D%5Bi%5D%5BJ16879598%2CY%5D">

<p>Hard coded charts with SMH symbol:</p>
<img src="http://stockcharts.com/def/servlet/SharpChartv05.ServletDriver?chart=SMH%2Cuu%5Bm%2Ca%5Deaolynay%5Bd20%5D%5Bph.02%2C.20%21f%5D%5Bi%5D%5 BJ16879598%2CY%5D">
<img src="http://stockcharts.com/def/servlet/SharpChartv05.ServletDriver?chart=SMH%2Cuu%5Bm%2Ca%5Ddaolynay%5Bda%5D%5Bph.02%2C.20%21f%5D%5Bi%5D%5B J16879599%2CY%5D">
<img src="http://stockcharts.com/def/servlet/SharpChartv05.ServletDriver?chart=SMH%2Cuu%5Bm%2Ca%5Ddaolynay%5Bdc%5D%5Bph.02%2C.20%21h.006%2C.017%2 1f%5D%5Bi%5D%5BJ16879600%2CY%5D">
<img src="http://stockcharts.com/def/servlet/SharpChartv05.ServletDriver?chart=SMH%2Cuu%5Bm%2Ca%5Dwaolynay%5Bdb%5D%5Bph.02%2C.20%21f%5D%5Bi%5D%5B J16879601%2CY%5D">

</body>
</html>

glenngv
05-03-2004, 06:05 AM
It can be done in javascript but it is better done in server-side because if javascript is disabled, no image will be displayed. Do you have access to the servlet?

chelentano
05-03-2004, 06:09 AM
It can be done in javascript but it is better done in server-side because if javascript is disabled, no image will be displayed. Do you have access to the servlet?
No, Glenn, I don't. That's why it should be, I think, in JavaScript.

chelentano
05-03-2004, 06:31 AM
I also tryed this:
<img src="http://stockcharts.com/def/servlet/SharpChartv05.ServletDriver?chart="+myVar+"%2Cuu%5Bm%2Ca%5Ddaolynay%5Bda%5D%5Bph.02%2C.20%21f%5D%5Bi%5D%5BJ16879599%2CY%5D">

but it displays wrong (Dow not IBM) chart.

glenngv
05-03-2004, 07:51 AM
Do you mean this?


<html>
<head>
<script type="text/javascript">
function createImage(chart, str){
document.write('<img src="http://stockcharts.com/def/servlet/SharpChartv05.ServletDriver?chart="'+chart+str+'" />');
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
<input type="text" name="textfield">
</form>

displayImage('IBM','%2Cuu%5Bm%2Ca%5Deaolynay%5Bd20%5D%5Bph.02%2C.20%21f%5D%5Bi%5D%5BJ16879598%2CY%5D ');
displayImage('SMH','%2Cuu%5Bm%2Ca%5Dwaolynay%5Bdb%5D%5Bph.02%2C.20%21f%5D%5Bi%5D%5BJ16879601%2CY%5D' );
...
</body>
</html>

But I don't see any difference in hardcoding the image instead because the part after the IBM or SMH (those with %s) also changes.

I have a feeling that what you really want is when IBM is entered in the textbox, the image changes accordingly.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum