Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    adding variable to IMG tag

    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>
    Last edited by chelentano; 05-03-2004 at 06:02 AM.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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?

  • #3
    New Coder
    Join Date
    Jul 2002
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv
    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.

  • #4
    New Coder
    Join Date
    Jul 2002
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Do you mean this?
    Code:
    <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.


  •  

    Posting Permissions

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