• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use variables in a javascript from the same JSP

 
Jibesh Patra
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have got a JSP . On the top of the page I have got a javascript code. Now a variable is declared in the Javascript code, I want to use that variable in my JSP.
How do I do that please help !!!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's important to understand is that Javascript is interpreted on a different machine than your JSP code, at a different time.
Since Javascript is the result of your JSP's execution, it can only be interpreted (in the browser) after the JSP execution has finished.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this article to understand how JSP works.
 
Prafulla N. Patil
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
temporary workaround for this can be as follows

you can try putting textbox in your jsp and then set the value of the variable to that textbox and then you can access that value once jsp is processed.

but thats true that you can access javascript variable directly in the same JSP
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Prafulla N. Patil:
temporary workaround for this can be as follows


There really isn't a workaround for not understanding this fundamental web programming concept. I think the original poster will do much better if (s)he stops and takes the time to understand this. Handing him/her a workaround or patch that gets something working without the need for this understanding will hurt more than help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic