• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Assigning JSP variable to JavaScript

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am calling a javascript method in anchor tag on onclick event. my problem is , method is not called on onclick and not giving any Error.

Method----
function exportcsv1(uid){
alert("Test");
alert(uid);
}

uid is a variable of jsp


Regards
Prem
 
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Do the following :



Best of luck ...
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSP and JavaScript can't really share data since JSP is server-side code ( it runs and creates the final HTML that the browser displays ) while JavaScript is client-side code which runs on the browser.

The workaround, for values that will not change as the user work on a page is the method that Vassili Vladimir gave you above. You 'print' out the value of the server-side variable into the HTML that your send as the response.
[ September 21, 2007: Message edited by: Tarun Yadav ]
 
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by premgwl rai:
Hi All,

I am calling a javascript method in anchor tag on onclick event. my problem is , method is not called on onclick and not giving any Error.

Method----
function exportcsv1(uid){
alert("Test");
alert(uid);
}

uid is a variable of jsp


Regards
Prem




call the function as below.
exportcsv1(<%= uid%>)

pass the value of variable uid to javascript function using expression.

it will generate html like this
exportcsv1(sud)
 
Whatever. Here's a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic