wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Access javascript variable in java without submitting form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Access javascript variable in java without submitting form" Watch "Access javascript variable in java without submitting form" New topic
Author

Access javascript variable in java without submitting form

Sonal Jogi
Greenhorn

Joined: Oct 19, 2004
Posts: 23
Hi,

I have to access a javascript variable in java but without submitting the form. Is there any way to do it?
For e.g. i have a function
function google_ad_request_done(google_ads) {

if (google_ads.length < 1 )
return;

//some other working
}
I have to know the length of google_ads array. Any help would be appreciated.

Thanks in advance,
sonal
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You can look into Ajax to post data back.

Seach google for Ajax JavaScript
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60056
    
  65

Or search for "XMLHttpRequest" (same technology) which allows you to make a "behind the scenes" request to the server without refreshing the containing page.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sonal Jogi
Greenhorn

Joined: Oct 19, 2004
Posts: 23
Hi,

Thanks for the prompt reply. But the thing is, I am making the request to an external server (google) and, It in turn is calling the function I had defined, and returns the google_ad array. AJAX requies server side programming also which i cannot do, cause server is outside my scope.

Could you please suggest some other alternative.

Thanks & regards,
sonal
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You use the XMLHttpRequest back to your server which does the request to google's server.

If you can not do that then it sounds like you are out of luck.

Eric
Sonal Jogi
Greenhorn

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

It does seem like that.

Anyways, Thanks a lot!!

Regards,
sonal
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Access javascript variable in java without submitting form
 
Similar Threads
Regarding struts buttons
assign var to java variable
Javascript variable inside jsp scriplet
getting null value, from a variable being sent from JavaScript in the page
JS Error ACCESS IS DENIED when submitting the form in jsp file through javascript