Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javascript var inside a EL List's index

 
Chetan Pandey
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the folowing requirement:

func(index){

${requestScope.list[XX].title}

}

Instead of the XX above I want to use the javascript 'index' variable.

I have tried <c:set var="ind1">index</c:set>

${requestScope.list[ind1].title}
${requestScope.list['${ind1}'].title}


and several other ways. to no avail including scriptlets

any ideas.

Thanks

CP
 
D. Ogranos
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is not going to work. Your function func() is javascript, which is executed in the client (the browser). The EL expression ${requestScope...} is executed on the server, before the page even arrives at the client.

If you want to choose something from that list (which is on the server) based on a user action in the client, you will have to make another request to the server (either a form submit, or an AJAX request).

OR, you could write all the values in the list on the page, as javascript instructions, and then have your function select from that.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64975
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this article to understand JSP and why you cannot do it that way.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic