Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do i pass values to a javascript file

 
Anil Verghese
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a jsp page with a hidden variable, I want to access this value in a js file which is in another folder.. Can any one give me a sample code for it

Regards
Anil
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you familiar with how JavaScript can use the page DOM to access form elements? If not, here's an introduction.
 
Anil Verghese
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

Thanks for replying .. but the site does not say anything about passing values across different js files or atleast to call a function in a js file(in another folder) from a jsp
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The browser imports all of your JS files when it assembles the web page.
In other words, they all, in effect, become the same page.

If you declare a variable before importing a JS file, that variable will be available to the functions within it.
 
Anil Verghese
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I have a jsp page with script in it. I have a hidden field in the jsp whose value i am getting into my script portion in the jsp file. I want to pass this value to another javascript file ... these files are in different folders..
how can i pass values between these two files?

Regards
Anil
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, your js files are all loaded by the browser when the page is assembled.
They're not interpreted as separate entities.

Lets suppose you have some code in a js file named ext.js.
In that file there are functions that need the contextPath of your application. Assign the value of your contextPath to a variable, then import the file and that variable will be available to the functions in that file.


ext.js


Now in your JSP page:
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic