| Author |
passing a jsp variable as an argument to he javascript
|
Hari priya
Ranch Hand
Joined: Mar 11, 2004
Posts: 134
|
|
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 %>')"/>
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
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 +"')"%>'/>
|
Merrill
Consultant, Sima Solutions
|
 |
Hari priya
Ranch Hand
Joined: Mar 11, 2004
Posts: 134
|
|
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
Joined: Mar 11, 2004
Posts: 134
|
|
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
Joined: Mar 11, 2004
Posts: 134
|
|
|
...and BTW thank you very very much Merrill. I have been struggling to get this working since yest..
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
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 +"')"%>"/>
|
 |
 |
|
|
subject: passing a jsp variable as an argument to he javascript
|
|
|