TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Javascript, AJAX, E4X (http://www.talkphp.com/javascript-ajax-e4x/)
-   -   how would i echo this javascript variable (http://www.talkphp.com/javascript-ajax-e4x/3699-how-would-i-echo-javascript-variable.html)

sarmenhb 12-03-2008 05:38 AM

how would i echo this javascript variable
 
i'm trying to echo this variable to the screen

Code:

thumbs = document.getElementById("thumbnailPane").getElementsByTagName("img");
the way i am echoing the value out is i have a div named output so i did

Code:

document.getElementById('output').innerHTML = 'field: ' + thumbs;
but when i did that i get this

Code:

field: [object HTMLImageElement]
is there another way of doing it?

here is the whole peice of js code i'm using if ur interested.

Code:

window.onload = initPage;

function initPage() {
 
  thumbs = document.getElementById("thumbnailPane").getElementsByTagName("img");

 
  for (var i = 0; i < thumbs.length; i++) {
    image = thumbs[i];
       
        //myoutput:
        document.getElementById('output').innerHTML = 'field: ' + thumbs;

    image.onclick = function() {
   
      detailURL = 'images/' + this.title + '-detail.jpg';
      document.getElementById("itemDetail").src = detailURL;
         
      getDetails(this.title);
         
    }
  }
}

i also tried doing thumbs[i] and echoing the image variable but it shows the same output.

Karl 12-03-2008 02:06 PM

That's the correct behaviour because thumbs is an object. As JavaScript is very OOP. So you will need to access its methods. Such as like to get the actual SRC of the image, use the following:

javascript Code:
var source = thumbs.getAttribute('src');
alert("Image's Source is: " + source);


All times are GMT. The time now is 08:38 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0