aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes How do i pass values to a javascript file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How do i pass values to a javascript file" Watch "How do i pass values to a javascript file" New topic
Author

How do i pass values to a javascript file

Anil Verghese
Ranch Hand

Joined: Oct 11, 2006
Posts: 155
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
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
Are you familiar with how JavaScript can use the page DOM to access form elements? If not, here's an introduction.


Ping & DNS - updated with new look and Ping home screen widget
Anil Verghese
Ranch Hand

Joined: Oct 11, 2006
Posts: 155
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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Anil Verghese
Ranch Hand

Joined: Oct 11, 2006
Posts: 155
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

Joined: Dec 11, 2004
Posts: 13410

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:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do i pass values to a javascript file
 
Similar Threads
File constructor
requested resource (first.jsp) not available
Adding a file to a program
JMF
Ant error: Make sure you have it in you classpath