Click to See Complete Forum and Search --> : Variable xx.js source ?


pmugghc
12-21-2002, 09:08 PM
WHen yoiu invoke a file with JavaScript, can't the name be a variable ? I tried the following, but it didn't work:

<HTML>
<HEAD>
<TITLE>Test
</TITLE>

<script language="JavaScript" type="text/javascript">
textString = "";
select1 = "t1.js";
</script>

</HEAD>

<BODY BGCOLOR="#FFFFFF">

<CENTER><U><H2>
Roland's Test
</CENTER></U></H2>
<P>
<SCRIPT LANGUAGE="JavaScript" src=select1>
</script>

<script language="JavaScript" type="text/javascript">
document.write("<p>Text: " + textString + "</p>");

</script>


</HTML>

The t1.js contains:

<!-- Begin
textString = "1";
// End -->

khalidali63
12-21-2002, 10:53 PM
yes that won't work...anything before script> tags beginning is not processed by JavaScript engine.
though,you may want to try this approach,I am positive it will work,only that you have to be very carefull about the quotes and stuff

try this

Roland's Test
</CENTER></U></H2>
<P>
<SCRIPT LANGUAGE="JavaScript">
//line below must be 1 line
document.write("<SCRIPT LANGUAGE=\"JavaScript\" src=select1><\/script> ");

</script>

pmugghc
12-21-2002, 11:41 PM
I tried it, couldn't get it to work neither in IE nor Nescape.

Can you have scripts within scripts ?

Thnaks, Roland