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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing JS string variable to HTML file...SIMPLE!

Status
Not open for further replies.

Ads

Programmer
May 29, 2001
17
0
0
CA
I need to pass a variable from a js file into a html document for writting purposes. For example:

JS file (text.js)
-----------------

var wC='Hi my name is...'

HTML file (index.html)
----------------------

<html>
<body>
<script language=&quot;javascript&quot; src=&quot;text.js&quot;>
document.write(wC)
</script>
</body>
</html>

QUESITON: How come I this doesn't work? It logically makes sense to me, but am unsure why it will not print the variable extraced from the JS file. I know the files are in the same directory...
Can anyone help?



 
You need to do add a couple of extra script tags. I think it do do with the Javascript interpreter not parsing the include script until it encounters a closing tag.

<html>
<body>
<script language=&quot;javascript&quot; src=&quot;text.js&quot;></script>
<script>
document.write(wC)
</script>
</body>
</html>

Greg.
 
It totally worked...
Thanks alot, that would have caused hours of wasted frustration..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top