This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Print javascript variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Print javascript variable " Watch "Print javascript variable " New topic
Author

Print javascript variable

Sonal Jogi
Greenhorn

Joined: Oct 19, 2004
Posts: 23
Hi,

I have a variable and i want to print its value as comment (not front end), so that the value can only be checked in view source. Its something like this:
document.write("<!-- No of links Received = "+ google_ads.length+ "-->");
But in this case, when we do view source, we are able to simply see the same statement and not the actual value of google_ads.length. Could anyone please help?

Thanks in advance,
sonal
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Of course you are not going to see the stuff on the screen, that is the way that it works. It is not like a server side code with a Response.write, the server puts that in the page as it renders, client side code basically puts it into memory.

if you want to see the stuff on the screen you need type this into your address bar:

javascript:alert(document.body.innerHTML);

Eric
Sonal Jogi
Greenhorn

Joined: Oct 19, 2004
Posts: 23
Hi Eric,

U r absolutely right in that but i dont want to print it on screen. Its for validation purposes that i have to log the length of the array as html comment. But in the above case when i do a view source, i see the same sattement whereas i want it to be like document.write("<!-- No of links Received = "+ 10 + "-->"); where 10 is the actual length of the array.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
The view source is grabbing the document from cache not the source, there is no way for you to see the value that the page renders.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Print javascript variable