aspose file tools*
The moose likes JSP and the fly likes Use JavaScript Variable In Side Java Code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Use JavaScript Variable In Side Java Code" Watch "Use JavaScript Variable In Side Java Code" New topic
Author

Use JavaScript Variable In Side Java Code

Sameera Abeysekara Abeysekara
Greenhorn

Joined: Apr 10, 2007
Posts: 19
I want to access java script variable in side java code in JSP

How can i do this?

i wrote following code but that one is not working.

function fillData(){
test=document.getElementById('adduser').employeeNumber.value

<%
if(test==71){%>

document.getElementById('adduser').employeeName.value="Sameera";
<%
}
%>

}

(i want to "test" variable access in side the java code)

Thanks
Sameera
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

I think its impossible, because the <% Java code %> inside a JSP page is executed on the server side and produces an HTML page, while the JavaScript code is executed on the client. When the HTML page reaches to the client, the Java code is not present anymore.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Muhammad Saifuddin:
I think its impossible, because the <% Java code %> inside a JSP page is executed on the server side and produces an HTML page, while the JavaScript code is executed on the client. When the HTML page reaches to the client, the Java code is not present anymore.


Muhammad is correct.
Your Javascript is nothing more than output text as far as the JSP environment is concerned.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60055
    
  65

Please read this article to understand the JSP life cycle.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Use JavaScript Variable In Side Java Code
 
Similar Threads
Easy way to create and manipulate XPath strings in JavaScript?
form in multilingual
how to set javascript varibale in <s:url><s:param> value attribute
know the current status of command button
how to use jsp variables in javascript