Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: can a variable be used to store image

  1. #1
    Join Date
    Nov 2007
    Posts
    69
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Default can a variable be used to store image

    hi
    i m not sure but wanted to use a variable to store an image and then show it inside the table
    something like
    Code:
    var img1;
    img1="c:\myself.jpg";
    
    and inside the table it shows like
    <table>
    <td>img1</td>
    </table>
    and this way it shows the image
    is there a way to do such a thing
    pls advice
    smile always
    anand

  2. #2
    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

    You can display images wherever you like, but you must involve the image tag at some point. This would work:

    Code:
    <script type="text/javascript">
    var img1;
    img1="c:\myself.jpg";
    </script>
    
    <table>
    <td><script type="text/javascript">
    document.write('<img src="'+img1+'">');
    </script></td>
    </table>
    Also, with server side language you can do it more like what you have, but still not so simply. However, this is the javascript forum, so I have given you a javascript answer. There are other ways, even in javascript, but they all involve some tag (usually an image tag, the object tag can be used in some browsers with some image types) to display the image.
    - John
    ________________________

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

  3. #3
    Join Date
    Nov 2007
    Posts
    69
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Default

    sir,
    thanks for your help
    can you suggest me some other way to make it function because i m not able to display the pic
    i m posting the code for reference
    the td area marked as red is where i want to put the image
    it wud be really kind of you if you can help me in this regard

    Code:
    function getSearchResults()
            {try
            	{
    	         var para = document.getElementById("txtSearchPara").value;
            	  var dbfile = getDBFile(); 
            	  var cn = new ActiveXObject("ADODB.Connection");
    		   var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source ="+ dbfile+ ";Persist Security Info=False";
                cn.Open(strConn);
                var rs = new ActiveXObject("ADODB.Recordset");
                var SQL = "select *  from test where " + 
                "clid like '%" + para + "%' or " + 
                "tel2 like '%" + para + "%' order by clid desc";
    		
                rs = cn.Execute(SQL);
                var resultString = "<table>";
                		resultString = resultString + "<tr> " +
                		"<td></td>" + 
    "<td></td>" + 
    			"<td></td>" +
                	"</tr>" ;
    			
                var a1;
                var a2=0;
                var color;
                var bcolor;
                while (!rs.EOF ) 
                	{
                	color="#348781";  // green colour
    		bcolor="white";
                	
                	
                		resultString = resultString + "<tr> " +
    				"</tr>" +
    				"</table>" +
    				"<table>" +
    					"<tr>" +
    					"<td>" +"Stitching Number-"+ rs("clid")+"</td>"+
    					"<td>" + "Trial Date-" +  rs("tdat")+ "</td>" +
    					"<td>" + "Delivery Date-" +rs("ddat")+ "</td>"+
    				"</tr>";
                	rs.MoveNext();
                	}
                	resultString = resultString + "</table>";
                rs.Close();
                cn.Close();
            document.getElementById("SearchResultPanel").innerHTML=resultString;
               }
               catch (e)
               {
               	alert ("getSearchResults() : " + e);
               }
            }
            </script>
    </head>
    <body onload= getSearchResults(); >
    
    <div>
    	<table >
    		<tr>
    		    <td>
    			<input type="text" name="txtSearchPara" tabindex="19" onblur = "getSearchResults();">
    		   </td>
    		</tr>
    		<tr>
    		<td><SPAN id= "SearchResultPanel" style = "position: relative; width: 100%; "></SPAN>
    		</td>
    when i try to use ur code inside that td box it does not show any thing on page .must be some other way to do this thing
    pls help
    smile always
    anand

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Code:
    var resultString = "<table>"; 
    resultString = resultString + "<tr> " + 
     "<td></td>" + 
     "<td><img src='"+img1+"'></td>" + 
     "<td></td>" + 
    "</tr>" ;
    Just keep in mind that you need to assign the variable img1 before this will actually work.
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. The Following User Says Thank You to thetestingsite For This Useful Post:

    meenakshi (07-03-2008)

  6. #5
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    TheTestingSite: Whats the difference between your code and this code?:
    Code:
    var resultString = "<table>"; 
    resultString = resultString + "<tr>
    <td></td>
    <td><img src='"+img1+"'></td>
    <td></td>
    </tr>";
    Jeremy | jfein.net

  7. The Following User Says Thank You to Nile For This Useful Post:

    meenakshi (07-03-2008)

  8. #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 Nile View Post
    TheTestingSite: Whats the difference between your code and this code?:
    Code:
    var resultString = "<table>"; 
    resultString = resultString + "<tr>
    <td></td>
    <td><img src='"+img1+"'></td>
    <td></td>
    </tr>";
    In the highlighted section of your version the line ends without a terminating quote or a continue signifier. So, in all likelihood the script parser will barf on it. This is different than using 'echo' in PHP where the line break at the end of the line is seen as part of the string value. In javascript, lines that do not end in ; are still considered to end by most script parsers. Some browsers are better at guessing which lines should end, and which should not in javascript. But by the very nature (informal) of the language, it is impossible for any parser to guess right all of the time.

    That's why (in javascript) it is best to actually use the ; for line ends, even though it isn't always required, and why termination with a concatenation signifier is required for most lines that 'continue below'.
    - John
    ________________________

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

  9. The Following User Says Thank You to jscheuer1 For This Useful Post:

    meenakshi (07-03-2008)

  10. #7
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I see, so if you put all the script on the same line it'd execute fine in all browsers?
    Jeremy | jfein.net

  11. #8
    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 Nile View Post
    I see, so if you put all the script on the same line it'd execute fine in all browsers?
    Which script? Um, it doesn't matter though. If you do that and haven't properly terminated your statements with semicolons, that will give rise to problems. But scripts can be all one line, if written properly.
    - John
    ________________________

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

  12. #9
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Hmm, I see. Thanks for the info .
    Jeremy | jfein.net

  13. #10
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

  14. The Following User Says Thank You to techietim For This Useful Post:

    meenakshi (07-03-2008)

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
  •