• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How pass an integer array to a javascript funcion

 
k kousalya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai all,
can any one please tell me how pass an integer array to a javascript function. I have one jsp page. In that page i have written one javascript function "display(intArray)". I am passing integer array to this function from jsp page. But if i display the values of the array it is showing "NaN".
my javascript function is


I am passing the integer array to display(opion) is::



Thanks in advance
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you trying to pass a *Java* array to a JavaScript function?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSP executes on the server, the JavaScript on the client long after the JSP has finished executing and gone away.

Please read this article tounderstand how JSP works and why what you are asking is impossible.

Rather, use JSP to create the data in JavaScript markup.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My advice is to write a static HTML page with exactly the kind of Javascript you want, including the array of integers the way Javascript wants to see it.

With that as a working example, figure out how you can get JSP to write it.

Bill
 
Eduardo Bueno
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try passing the array via String. If you have a pageBean, that's easy to do:
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eduardo Bueno wrote:Try passing the array via String.

Again, that is not "passing the array" -- which you cannot do.

That's using JSP to create JavaScript markup just as William and I have advised.
 
Andy Crane
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a suggestion, there may already be an object out there that will take an array in java and output a JSON formatted string that you can use.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic