• Post Reply Bookmark Topic Watch Topic
  • New Topic

Assigning JSP variable to JavaScript  RSS feed

 
sonu rai
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Do the following :



Best of luck ...
 
Tarun Yadav
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • 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 ]
 
sudhir nim
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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)
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!