• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't figure out how to pass a variable to javascript

 
Stamin Adrian
Ranch Hand
Posts: 34
Chrome Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


In the onClick event, how do I send the ${i.username} value? I need to pass two variables.
 
Rafael Prado Oliveira
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
not quite sure but you will need use quotes in the ${'i.value'}
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't directly pass it. The value exists on the server, but the script runs on the client after the page is created and sent.

What you can do is to use JSP to create valid JavaScript syntax to be evaluated later.

See this article if that is confusing.
 
Stamin Adrian
Ranch Hand
Posts: 34
Chrome Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


How about this? It doesn't work, how can i reference to that input better? Are you positive that reading that big article will help? It doesn't seem like it.
 
Rafael Prado Oliveira
Greenhorn
Posts: 28
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stamin Adrian wrote:

How about this? It doesn't work, how can i reference to that input better? Are you positive that reading that big article will help? It doesn't seem like it.



try '${i.username}'
 
Stamin Adrian
Ranch Hand
Posts: 34
Chrome Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You we're right. After all you can reference it directly. The '${i.username}' worked. Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stamin Adrian wrote:After all you can reference it directly.

No, you can't. JavaScript cannot directly reference scoped variables on the server. All you are doing is writing text to a buffer. That text is sent as the response with the value of the expression hard-coded into the response. That's a really important distinction. There is no direct referencing going on here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic