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

passing a jsp variable as an argument to he javascript

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

I need to send a jsp variable to the javascript fucntion. Some how it is not working well. Can any one suggest me a way to do it?
The following alert prints <%= id %> in the alert box but not the value.
Any ideas on how to do it?
GOAL:
The check box is in the logic:iterate tag and my goal is to associate an id to the check box and pass it to the javascript variable.

function view(id){
alert(id);
}

<html:checkbox property="user" onKlick="view('<%= id %>')"/>
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is possible to use run-time expression in an attribute of an <html:xxx> tag, but the rule is "all or nothing", meaning that the whole attribute must be a run-time expression, or else none of it can be a run-time expression.

With that in mind, the following should work:

<html:checkbox property="user" onKlick='<%="view('"+ id +"')"%>'/>
 
Hari priya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Merrill,

Firstly, many thank for tyrign to help me out.
I tried that but the checkbox completely vanished.
This is what I see when I click the view source.

 
Hari priya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Meriill,

Actually, I had to make a slight modification to your code and it worked. Its just that I had to place the quotes crrectly... let me post it here so that it might be helpful to some one.

 
Hari priya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...and BTW thank you very very much Merrill. I have been struggling to get this working since yest..
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome. Glad you got it working.

The tricky thing about this is to make sure you don't have single quotes inside single quotes or double quotes inside double quotes. I believe the reason the first attempt made the checkbox disappear was because we had single quotes within single quotes. Your modification of the code works because the "id" variable resolves to a number, but if it resolved to a String, it wouldn't work. I think this would work in all situations:

<html:checkbox property="user" onKlick="<%="view('"+ id +"')"%>"/>
 
reply
    Bookmark Topic Watch Topic
  • New Topic