Brett_Tabke

msg:1473317 | 12:58 pm on Jul 10, 2001 (gmt 0) |
Hi Medic and welcome to the board. Sure you can: document.write('<script src="http://foo.com/myjs.js">'); document.write('</script>');
|
medic

msg:1473318 | 1:16 am on Jul 11, 2001 (gmt 0) |
Thanks for the reply Brett :-) Does it mean I can write a code like this: <script language="javascript"> function ValidateItem(obj){ var citem; var validflag=false; citem=obj.txtItemName.value; document.write('<script src="myjs.js">'); document.write('</script>'); if (validflag) { /* place my codes here */ } else { alert("Invalid Item") } } </script> My purpose here is to execute the codes in MY.JS immediately after the "citem=obj.txtItemName.value;" then execute the "if (validflag)..." statement. Do I get it right?
|
medic

msg:1473319 | 1:48 am on Jul 11, 2001 (gmt 0) |
duh..... why can't it work? am i missing something or did something not right?
|
tedster

msg:1473320 | 10:21 am on Jul 11, 2001 (gmt 0) |
A couple of thoughts. The problem with this may be that you end up with a <script> tag nested in a <script> tag. Have you tried three separate script tags: <script language="javascript"> function ValidateItem(obj){ var citem; var validflag=false; citem=obj.txtItemName.value; </script>
<script type="text/javascript" language="JavaScript" src="myjs.js"></script>
<script language="javascript"> if (validflag) { /* place my codes here */ } else { alert("Invalid Item") } } </script>
Here's another angle you might try. When the HTML parser hits '</script>' in the second document.write statement, it stops the currently running script. You could test this by writing the second statment as: document.write('</' + 'script>'); --but you may still have problems because of the nested script tags. If all else fails, load the page in Netscape and see what their javascript console has to say (type javascript: in the location window).
|
medic

msg:1473321 | 10:58 am on Jul 13, 2001 (gmt 0) |
Thanks for the reply Ted, I tried your advise but it seems that "calling an external Javascript from a Javascript" is really a dream for now (at least for me). :-)
|
MikeFoster

msg:1473322 | 10:39 pm on Jul 24, 2001 (gmt 0) |
Hi Tom! medic, here's another idea: Here's the file myjs.js: function doSomething() { ... }
Now, after myjs.js is included in the html file (as on line 4), all the functions defined in myjs.js will be available and can be called from within SCRIPT elements in the html file (as on line 10). 1: <html> 2: <head> 3: 4: <script type="text/javascript" src="myjs.js"> </script> 5: 6: <script type="text/javascript"><!-- 7: 8: window.onload = function() { 9: 10: doSomething(); 11: } 12: 13: //--></script> 14: </head> 15: <body> 16: 17: </body> 18: </html>
|
medic

msg:1473323 | 8:05 am on Aug 6, 2001 (gmt 0) |
Thanks for the help guys, especially to you Tom! That was a great tip!
|
phzzz

msg:1473324 | 1:10 am on Aug 7, 2001 (gmt 0) |
You are very welcome Medic. I knew the solution was the correct one, even before I posted. :) Mike Foster is also very good as well. He co-moderates a "different" forum with me in Webmastering/HTML at another board, but that board will remain nameless here, due to proper "netiquette". LOL! :) We respect this practice and abide by it at all times. Take care! ...Tom
|
|