JavaScript element into a Java variable

Hello,
Thanx 4 readin this.

I have an issue where in i need to pass the value that i get in a javascript block to a Java variable.

Something like this:

index.jsp:

<script language = "Javascript">
var x ="myname";
</script>

<% String cp = x%>
.....
..........


don worry abt the syntax..I need something like that.
How do i pass a java script varaible to a String variable of Java?
I know that Javascript runs on client and Java is something on Server so and cannot set a value on server thru script.
But i guess there is some possible way ...

Anyone any ideas??

Thanx & Regards.
talktome_prashanthAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bloodredsunCommented:
Basically, you can't put a javascript variable in a scriptlet because, as you mention, the java scriplet runs on the server before the javascript is run on the client machine, so the simple answer is no.

The only way would be to submit a new HTTP request to the server with the Javascript variable as a request parameter and then pass it into the Java code on the next page.

The easiest solution to things like this is to dynamically create an array of javascript objects (using a Java scriptlet) and then access this using JavaScript.

Can you tell me exactly what you are trying to do and maybe I can come up with a better and more appropriate solution?
talktome_prashanthAuthor Commented:
Thanx bloodredsun,

This is development in the SAP Portals.
The page has two iframes.One iframe fires an event like fires and event when a selection is made in the dropdown Box.
The other iframe catches the item chosen from DropDownBox in the javascript block.I can alert and it works fine.

Now i need to update a url based on this variable.
How do i pass the url to the src attribute of iframe.
can i use a javascript function in the src??

<iframe id="d1" src="" >

</iframe>
 Thanx
bloodredsunCommented:
>>can i use a javascript function in the src??

Yes, you just need the correct call:
somehting like :
var newValue = "blahblah" ;
parent.getElementById("d1").location.href = newValue ;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
talktome_prashanthAuthor Commented:
Thanks again,
Can u explain how cud i achieve something u said in ur first reply?

>The only way would be to submit a new HTTP request to the server with the Javascript variable as a request parameter >and then pass it into the Java code on the next page.

>The easiest solution to things like this is to dynamically create an array of javascript objects (using a Java scriptlet) and >then access this using JavaScript

Please give me a code sample to show how cud i store a javascript variable and then access it in the Java ..


Thanks a million.
bloodredsunCommented:
Agreed
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.