0

I have encountered a situation where I have to assign the value of a JavaScript variable into Java variable. Please suggest me a way to do it.

P.S: Assigning value of Java variable into JavaScript is something like this:

< Script>< %

String str = "abcd";

%> var x = <%= a %>; /Script>

I have to do opposite of it.

2 Answers 2

1

If Java is being used as the server-side language, by the time the page has been sent, Java has long finished (it doesn't run after the page has loaded). You may make a request to a page, sending the variable with the request, and that page may have Java handle the variable, though.

Sign up to request clarification or add additional context in comments.

Comments

0

It is not even clear what you are doing, but I assume that the snippet you show is part of a template for a web page. You will not be able to get the variable directly - JavaScript will be running on another computer some continents apart!

But you can make the client communicate with the server, using AJAX.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.