Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

External JavaScript Not Running 2

Status
Not open for further replies.

xyzuser

Technical User
Aug 13, 2008
96
US
I am not experienced in using JavaScript. I am trying to use an external JavaScript that I put into a directory js . I need to set a variable, in each html file, that will be used by the external JavaScript file to set a link to a specific URL, depending upon which html file is calling it

Here is my code (in the Body):
Code:
<script type="text/JavaScript">
<!--//
myvar1="/FileA.html"
<script src="/jscript/Menu01.js" type="text/JavaScript">
//-->
</script></script>
I do not get an error when I run it but the external JavaScript is not executing.

What am I doing wrong?
 
I forgot to say that the JavaScript code does execute properly when I put the code inline in the HTML. So I know that the code itself works.
 
The code you've posted isn't quite right - you are putting HTML inside a script block whose language you have specified as JavaScript. Try this instead:

Code:
<script type="text/javascript">
   var myvar1 = '/FileA.html';
</script>

<script src="/jscript/Menu01.js" type="text/javascript"></script>

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks BillyRayPreachersSon. I know what you wrote should work but it still does not work. My code is now:

Code:
<script type="text/"JavaScript">

myvar1="/FileA.html"
</script>

<script src="/jscript/Menu01.js" type="text/JavaScript">

</script>
I verified that the JavaScript is in the jscript folder. I even tried putting in the entire URL instead of just the "/" for the directory but that made no difference.
 
I don't know whether this makes any difference: the JavaScript code refers to a CSS style sheet using pseudo-classes that is defined within the HTML "Head".
 
[tt]<script type="text/[highlight]"[/highlight]JavaScript">[/tt]
[tt]<script type="text/JavaScript">[/tt]
 
I wound up doing that and now it works. Thank you very much for your help. And also for your quick response! It is really greatly appreciated!!

And thanks also tsuji for catching that typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top