| | |
Javascript: Passing Forms into Sub-routines
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2006
Posts: 88
Reputation:
Solved Threads: 2
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?
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?
•
•
Join Date: Aug 2008
Posts: 381
Reputation:
Solved Threads: 33
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
child script (test.js)
Didn't test this, but something like this is how I made it work before.
Cheers
...
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)
function load_script ( path ) { var head = document.getElementsByTagName('head').item(0); var script = document.createElement('script'); script.setAttribute( 'type', 'text/javascript' ); script.setAttribute( 'src', path ); head.appendChild( script ); } load_script( 'test.js' );
child script (test.js)
javascript Syntax (Toggle Plain Text)
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.
Google is the answer to all of your questions -- the trick is knowing what question to ask in your specific predicament.
![]() |
Similar Threads
- Help for learnign JSP (JSP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Tech help please.
- Next Thread: Engine for site on Java Script for free hosting without PHP, SQL
| Thread Tools | Search this Thread |
ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate array automatically browser bug calendar captchaformproblem cart checkbox child class close codes createrange() cursor date debugger dependent disablefirebug dom dropdown editor element embed engine events explorer ext file firefox form forms getselection google gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe images internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jsp jump libcurl maps masterpage math media microsoft object onmouseoutdivproblem onreadystatechange parent paypal pdf php player position post programming progressbar prototype redirect regex runtime safari scale scriptlets scroll search security shopping size software sql text textarea toggle unicode web website windowsxp wysiwyg \n





