can a variable be used to store image

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • meenakshia
    New Member
    • Jun 2008
    • 33

    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
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You could use document.create Element or the Image object constructor to create an image and then set its src, e.g.
    [code=javascript]var img = document.create Element("img");
    img.src="image. gif";[/code]

    Comment

    • meenakshia
      New Member
      • Jun 2008
      • 33

      #3
      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
      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);
              [B] [I][U]var img = document.createElement("img");
      	img.src="logo.jpg";[/U][/I][/B]
                  var resultString = "<table>";
                  		resultString = resultString + "<tr> " +
                  		[B]"[U]<td>" + img + "</td>" +[/U][/B] 
                              "<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>
      smile always:)
      anand
      Last edited by meenakshia; Jul 3 '08, 02:54 AM. Reason: some lines were missing

      Comment

      • realin
        Contributor
        • Feb 2007
        • 254

        #4
        Originally posted by meenakshia
        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.f iles.wordpress. com/2008/03/google_logo_.jp g";
        function create_img(){
        var div = document.getEle mentById("pop") ;
        var hold=document.c reateElement("i mg");
        hold.src=im;
        hold.border=2;
        div.appendChild (hold);
        }
        </script>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Untitl ed 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 !!

        Comment

        • hsriat
          Recognized Expert Top Contributor
          • Jan 2008
          • 1653

          #5
          If you want to use it like this: "<td>" + img + "</td>", then use img to store the HTML for the image.
          [CODE=javascript]var img = '<img src="logo.png" alt="logo" />';[/CODE]

          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.
          [code=javascript]document.getEle mentById('image Id').style.disp lay = '';[/code]

          Comment

          • meenakshia
            New Member
            • Jun 2008
            • 33

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

            Comment

            • hsriat
              Recognized Expert Top Contributor
              • Jan 2008
              • 1653

              #7
              Originally posted by meenakshia
              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

              Comment

              • meenakshia
                New Member
                • Jun 2008
                • 33

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

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Must be a pretty sad place where you live.

                  No wonder you always sign off with "smile always" ;)

                  Comment

                  Working...