•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 425,786 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,274 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1166 | Replies: 1
![]() |
| |
•
•
Join Date: Jul 2006
Posts: 73
Reputation:
Rep Power: 3
Solved Threads: 0
Hi, folks.
I have written some pretty complicated programs in Javascript (in terms of the code itself), but I haven’t experimented much with the nuts-and-bolts of Javascript. In particular, I have written all my programs as single blocks of code. For example, I have written several programs to solve for the eigenvalues and eigenvectors of matrices. One page solves for a 3 x 3 matrix, one for a 4 x 4 matrix, one for a 5 x 5 matrix, etc. Each javascript program is on its own page and takes the following form:
The algorithm for actually calculating the eigenvalues and eigenvectors does not change depending upon matrix size, it is included in the BIG BLOCK OF CODE.
What I am hoping to do now is turn the code block for the BIG BLOCK OF CODE into an external file, and have the several programs refer to it. That way, I won't have six programs include the same big block of code; they can all refer to the same external file--saving space on the server. For example:
Is what I want to do possible? How seamlessly does Javascript transmit data between seemingly independent code blocks?
I have written some pretty complicated programs in Javascript (in terms of the code itself), but I haven’t experimented much with the nuts-and-bolts of Javascript. In particular, I have written all my programs as single blocks of code. For example, I have written several programs to solve for the eigenvalues and eigenvectors of matrices. One page solves for a 3 x 3 matrix, one for a 4 x 4 matrix, one for a 5 x 5 matrix, etc. Each javascript program is on its own page and takes the following form:
<script language="javascript" type="text/javascript">
<!--Define JavaScript function.-->
function OneBigProgram(dataForm){
// Code to input the matrix elements for the specifically-sized matrix
. . .
// Code to calculate the eigenvalues and eigenvectors
// BIG BLOCK OF CODE
. . .
// Code to output the results for the specifically-sized matrix
. . .
// end of JavaScript-->
</script>The algorithm for actually calculating the eigenvalues and eigenvectors does not change depending upon matrix size, it is included in the BIG BLOCK OF CODE.
What I am hoping to do now is turn the code block for the BIG BLOCK OF CODE into an external file, and have the several programs refer to it. That way, I won't have six programs include the same big block of code; they can all refer to the same external file--saving space on the server. For example:
<script language="javascript" type="text/javascript">
<!--Define JavaScript function.-->
function A_Smaller_Program_Input(dataForm){
// Code to input the matrix elements for the specifically-sized matrix
. . .
// end of JavaScript-->
</script><script language="javascript" type="text/javascript" src="RoutineforEigenvalues.js"> </script>
function A_Smaller_Program_Output(dataForm){
// Code to output the results for the specifically-sized matrix
. . .
// end of JavaScript-->
</script>Is what I want to do possible? How seamlessly does Javascript transmit data between seemingly independent code blocks?
•
•
Join Date: Dec 2007
Posts: 75
Reputation:
Rep Power: 1
Solved Threads: 10
You have the right syntax. Just save your program as eigenValues3.js and then if you want to write a program that needs that file you just "import" it as follows:
Note: 1. You do not have to do the "import" within the <head> tag. It could have done withing the <body> tag.
2. <script> tags that are used to import files cannot enclose javascript code (or at least this was the case last time I tested this about 1yr ago). That's why I have two <script> tags above. The first one to import the file. The second to write my code for my local/current page.
3. You do not need language="javascript". Providing type="text/javascript" will suffice.
<html> <head> <script type="text/javascript" src="eigenValue3.js"></script> <script type="text/javascript"> //The code that will use the functions in eigenValue3.js goes here </script> </head> <body>... </body> </html>
Note: 1. You do not have to do the "import" within the <head> tag. It could have done withing the <body> tag.
2. <script> tags that are used to import files cannot enclose javascript code (or at least this was the case last time I tested this about 1yr ago). That's why I have two <script> tags above. The first one to import the file. The second to write my code for my local/current page.
3. You do not need language="javascript". Providing type="text/javascript" will suffice.
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
access activation ajax api asp blogger blogging blogs code combo cross-browser javascript menu with few lines of code dani daniweb data developer development dreamweaver dropdownlist firefox gdata google gpl home html internet javascript javascript smooth scrolling scroll smoothly window document position javascript tab menu with rounded corners generator key linux microsoft module msdn net news office openbsd product programming reuse rss serial software source tags vista web wysiwyg xml
- Browser Battle -- Your TOP Pick! (Geeks' Lounge)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Check Iframe compatability
- Next Thread: Complex Select generation with DOM


Hybrid Mode