Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pass variable in jsp to java script function ?

 
walter wang
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
How I need to pass a variable of JSP page to java script function as param.

How to do that? I tried below approach , but doesnot work out.
message is varible name
confirmLogOut is java script function

on click="return confirmLogOut(<%=message%>)


Could any of you give me some hints?

Thanks in advances

Sorry I have to put space between "on click". other wise i could submit this post


[ October 14, 2007: Message edited by: walter wang ]

[ October 14, 2007: Message edited by: walter wang ]
[ October 14, 2007: Message edited by: walter wang ]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Walter,
Note that you are not passing the message variable. Rather you are passing the value of the message variable. Since it is a string, you need to add the quotes to make JavaScript happy:

return confirmLogOut('<%=message%>')
 
walter wang
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Jeanne,

Thanks for your reply, after tring your appraoch
I found that,
it prints out " <%=message%> " as one whole string instead of content of it.
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And this did not work?

on click="return confirmLogOut("<%=message%>")"
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course you cannot pass a JSP value to JavaScript as the JSP is executing on the server and JavaScript executes on the client. Perhaps this article can help with that concept.

As Jeanne pointed out, you can write the value of the variable into the HTML but you need to make sure that the markup is correct. Do a View Source of the response sent to the browser to see what's being constructed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic