Forum Moderators: open
<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?
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, 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>
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