By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

can a variable be used to store image

meenakshia
P: 33
hi
i m not sure but wanted to use a variable to store an image and then show it inside the table
something like
Expand|Select|Wrap|Line Numbers
  1. var img1;
  2. img1="c:\myself.jpg";
  3.  
  4. and inside the table it shows like
  5. <table>
  6. <td>img1</td>
  7. </table>
  8.  
and this way it shows the image
is there a way to do such a thing
pls advice:)
smile always
anand
Jul 2 '08 #1
Share this Question
Share on Google+
8 Replies


acoder
Expert Mod 15k+
P: 16,027
You could use document.createElement or the Image object constructor to create an image and then set its src, e.g.
Expand|Select|Wrap|Line Numbers
  1. var img = document.createElement("img");
  2. img.src="image.gif";
Jul 2 '08 #2

meenakshia
P: 33
sir i m unable to use it properly pls check the code where i should make changes to make it work and get it displayed
sir,the area where i have inserted the code is in bold and unlined
in the result html it shows [object] as the display instead of the image
Expand|Select|Wrap|Line Numbers
  1. function getSearchResults()
  2.         {try
  3.             {
  4.              var para = document.getElementById("txtSearchPara").value;
  5.               var dbfile = getDBFile(); 
  6.               var cn = new ActiveXObject("ADODB.Connection");
  7.            var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source ="+ dbfile+ ";Persist Security Info=False";
  8.             cn.Open(strConn);
  9.             var rs = new ActiveXObject("ADODB.Recordset");
  10.             var SQL = "select *  from test where " + 
  11.             "clid like '%" + para + "%' or " + 
  12.             "tel2 like '%" + para + "%' order by clid desc";
  13.  
  14.             rs = cn.Execute(SQL);
  15.          var img = document.createElement("img");
  16.     img.src="logo.jpg";
  17.             var resultString = "<table>";
  18.                     resultString = resultString + "<tr> " +
  19.                     "<td>" + img + "</td>" + 
  20.                         "<td></td>" + 
  21.             "<td></td>" +
  22.                 "</tr>" ;
  23.  
  24.             var a1;
  25.             var a2=0;
  26.             var color;
  27.             var bcolor;
  28.             while (!rs.EOF ) 
  29.                 {
  30.                 color="#348781";  // green colour
  31.         bcolor="white";
  32.  
  33.  
  34.                     resultString = resultString + "<tr> " +
  35.                 "</tr>" +
  36.                 "</table>" +
  37.                 "<table>" +
  38.                     "<tr>" +
  39.                     "<td>" +"Stitching Number-"+ rs("clid")+"</td>"+
  40.                     "<td>" + "Trial Date-" +  rs("tdat")+ "</td>" +
  41.                     "<td>" + "Delivery Date-" +rs("ddat")+ "</td>"+
  42.                 "</tr>";
  43.                 rs.MoveNext();
  44.                 }
  45.                 resultString = resultString + "</table>";
  46.             rs.Close();
  47.             cn.Close();
  48.         document.getElementById("SearchResultPanel").innerHTML=resultString;
  49.            }
  50.            catch (e)
  51.            {
  52.                alert ("getSearchResults() : " + e);
  53.            }
  54.         }
  55.         </script>
  56. </head>
  57. <body onload= getSearchResults(); >
  58.  
  59. <div>
  60.     <table >
  61.         <tr>
  62.             <td>
  63.             <input type="text" name="txtSearchPara" tabindex="19" onblur = "getSearchResults();">
  64.            </td>
  65.         </tr>
  66.         <tr>
  67.         <td><SPAN id= "SearchResultPanel" style = "position: relative; width: 100%; "></SPAN>
  68.         </td>
  69.  
smile always:)
anand
Jul 3 '08 #3

realin
100+
P: 254
sir i m unable to use it properly pls check the code where i should make changes to make it work and get it displayed
sir,the area where i have inserted the code is in bold and unlined
in the result html it shows [object] as the display instead of the image

smile always:)
anand
hiya,

this can be done like this:
[HTML]
<html>
<head>
<script type="text/javascript" >
var im="http://technofriends.files.wordpress.com/2008/03/google_logo_.jpg";
function create_img(){
var div = document.getElementById("pop");
var hold=document.createElement("img");
hold.src=im;
hold.border=2;
div.appendChild(hold);
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<input type="button" onclick="create_img();" value="Create image" />
<div id="pop"></div>
</body>
</html>[/HTML]

hope this helps.. this works for me :)
cheers !!
Jul 3 '08 #4

hsriat
Expert 100+
P: 1,654
If you want to use it like this: "<td>" + img + "</td>", then use img to store the HTML for the image.
Expand|Select|Wrap|Line Numbers
  1. var img = '<img src="logo.png" alt="logo" />';
Or if you want the image to dynamically show up onclick of a button or something, then make it like this in your HTML:
[HTML]<img id="imageId" src="logo.png" alt="logo" style="display:none;" />[/HTML]

And with JavaScript, make it visible when required.
Expand|Select|Wrap|Line Numbers
  1. document.getElementById('imageId').style.display = '';
Jul 3 '08 #5

meenakshia
P: 33
hi hsriat
thanks a lot for the help
it worked and yes i m using it like +img+ inside the td tag
thanks once again:)
smile always
thanks forum
people like you are examples for how things should be done
really nice
god bless
anand
Jul 3 '08 #6

hsriat
Expert 100+
P: 1,654
hi hsriat
thanks a lot for the help
it worked and yes i m using it like +img+ inside the td tag
thanks once again:)
smile always
thanks forum
people like you are examples for how things should be done
really nice
god bless
anand
wow! :D
Thanks for appreciating our (forum's) work. :)

Regards,
Harpreet
Jul 3 '08 #7

meenakshia
P: 33
hi harpreet
well i mean it
because it feels so nice to see people helping each other where as in real life we dont find a single person supporting each other:(
good to see good and positive people around:)
smile always:)
anand
Jul 3 '08 #8

acoder
Expert Mod 15k+
P: 16,027
Must be a pretty sad place where you live.

No wonder you always sign off with "smile always" ;)
Jul 3 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.