943,774 Members | Top Members by Rank

Ad:
Aug 27th, 2008
0

Javascript: Passing Forms into Sub-routines

Expand Post »
I usually code all my Javascript in a single external file that accepts the data from a form in the main page's HTML textarea box.

Now I would like to break up this single Javascript file into separate files.
For example, I'd like to have main.js as the main controlling program which calls, say, input.js, do-computations.js, and output-results.js.

I would simply like to have main.js feed the textarea contents into input.js to parse the contents and assign all the data properly, to be passed back out to main.js.

Can this be done (is it simply a matter of feeding this.form from sub-routine, to sub-routine, to sub-routine, etc.)? Is there a limit to how deep into sub-routines a form element can be passed?
Similar Threads
Reputation Points: 33
Solved Threads: 9
Junior Poster
DavidB is offline Offline
188 posts
since Jul 2006
Sep 1st, 2008
0

Re: Javascript: Passing Forms into Sub-routines

I don't know what limit might be placed on such a thing ... but I built (can't find my example at the moment) a little function that creates a new javascript include element in the page header, effectively loading javascript on the fly (I used it for proof of concept loading php values as javascript without ajax)...

Try using the javascript DOM to write and append a <script> tag to the page header, and you should get the new javascript loaded dynamically in the page.

parent script
javascript Syntax (Toggle Plain Text)
  1. function load_script ( path ) {
  2. var head = document.getElementsByTagName('head').item(0);
  3. var script = document.createElement('script');
  4. script.setAttribute( 'type', 'text/javascript' );
  5. script.setAttribute( 'src', path );
  6. head.appendChild( script );
  7. }
  8.  
  9. load_script( 'test.js' );

child script (test.js)
javascript Syntax (Toggle Plain Text)
  1. alert( 'I am loaded' );

Didn't test this, but something like this is how I made it work before.

Cheers

...
Last edited by langsor; Sep 1st, 2008 at 3:42 am.
Reputation Points: 30
Solved Threads: 36
Posting Whiz
langsor is offline Offline
389 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Tech help please.
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Engine for site on Java Script for free hosting without PHP, SQL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC