File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Use JavaScript Variable In Side Java Code

 
Sameera Abeysekara Abeysekara
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1324
Android Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this article to understand the JSP life cycle.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic