Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing javascript array inside a div.

 
Rui Felix
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I'm having the following problem, I'm using AJAX to make a request to the server when I'm building the response I'm using a lot of javascript to be able to populate the checkboxes and handle information in Arrays. When I receive the response in my principal JSP I catch the response and put it in a DIV tag with the innerHTML property. Until here everything is ok and working fine but then the problems start :
1 : The HTML displayed doesn't have any check box selected. When I know that all check boxes has to be selected.
2 : Can't access to any array created by java script.

My real problem is that I can't access any javascript variables that I declare in the built response and that I set in the div.

Example of what I have:

RESPONSE in a JSP built like a XML FILE:


Now really simple question I think, how can I access to the variable CheckedArray in the principal JSP.

I thought it was interpreted like a local variable.

Thanks All
Texugo
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the HTML/Javascript forum.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to eval the javascript in the response. Basically you have to rip out the script tags and run eval. Prototype.js will do this for you with a setting in its Ajax handler.

Eric
 
Rui Felix
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Thank you, but I didn't understood where to use the eval function. The problem is when I do eval it isn't shown nothing.

I'm using eval when I accept the response from the server like the following:




Doing this [B][/B]
doesn't show nothing.

What property of prototype.js I have to trun on start doing that.

Thanks
texugo
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
eval is not a string method like that. You would have to strip out the JavaScript and run it seperately.

In the Ajax updater it has a property evalScripts:true

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic