• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

How to pass variable in jsp to java script function ?

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And this did not work?

on click="return confirmLogOut("<%=message%>")"
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Blood pressure normal? What do I change to get "magnificent"? Maybe this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic