aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes How to assign a javascript variable to java varisble? 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 "How to assign a javascript variable to java varisble?" Watch "How to assign a javascript variable to java varisble?" New topic
Author

How to assign a javascript variable to java varisble?

gokulanand narayanan
Greenhorn

Joined: Feb 16, 2006
Posts: 23
Hi All,

In my application i need to assign a javascript variable to java variable.

How can i achive this.

Thanks
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

java variable value can assign into javascript variable but you can't use javascript variable inside java code.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Use a hidden field, set the value with JavaScript and when the form posts, read the value.

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Java executes on the server. Javascript executes on the client.

Please read this article to see why your question doesn't make much sense.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pat Flickner
Ranch Hand

Joined: Nov 17, 2003
Posts: 173
Eric's absolutely correct, but you can take it a step further. If you need it to be on the same page, as soon as the javascript field is populated, have the page post to the same page and then look for that passed value from the input via the appropriate request method.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

But the point is, doing that without understanding the life cycle of a JSP is pointless. It's unlikely to achieve anything useful.
Pat Flickner
Ranch Hand

Joined: Nov 17, 2003
Posts: 173
No argument there. One should understand how it all works together. The best way that helped me understand how it all interacted was turning on both debugger in the javascript functions (if used) and running the processes in debug mode for the Java portion. That way you could see exactly what was being passed from the page to the Java code. Pretty cool to see how the information is extracted. Well, if you're me, it's pretty cool.

Anyway, if the questioner and whomever else is interested are smart, they'll read the article and play around so that they do understand what's going on. Otherwise, they'll be no better than many certified people I've had the displeasure of interviewing -- lots of knowledge (memorization) and no understanding or application.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to assign a javascript variable to java varisble?