Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JSP and the fly likes How pass an integer array to a javascript funcion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How pass an integer array to a javascript funcion" Watch "How pass an integer array to a javascript funcion" New topic
Author

How pass an integer array to a javascript funcion

k kousalya
Greenhorn

Joined: Jun 09, 2009
Posts: 12
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

Joined: Sep 29, 2008
Posts: 12617

Are you trying to pass a *Java* array to a JavaScript function?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61226
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12788
    
    5
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

Joined: Jun 04, 2009
Posts: 155
Try passing the array via String. If you have a pageBean, that's easy to do:
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61226
    
  66

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

Joined: Dec 30, 2008
Posts: 17
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.


- andy c
"Pseudo code first. If you can pseudo code accurately, when you start writing code, you're just applying syntax to the pseudo code. It separates the two most complicated pieces of programming into manageable bites. You create your app's workflow without worrying about syntax. Then you code without worrying about your app's workflow."
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How pass an integer array to a javascript funcion