PDA

View Full Version : Using a variable in the SRC tag


Gregg
10-02-2002, 04:17 AM
I have yet to find this in the online help, I am new so I am thinking this should work, but no proof.

I have inserted external scripts into my page. But I would like to do this with a variable. So I can change what script is inserted depending on what action the user takes.

currently my code looks like this:

var logo="logo.js"

<script src="+logo+">
</script>

I know the variable is valid becuse I have inserted the variable using a document.write

Of course I don't know if this is the correct way to approach this. But it seems logical.

Any help would be greatly appreciated.

thanks - Gregg

Carl
10-02-2002, 04:22 AM
Hi Gregg,

Try this,

<script language="javascript">
var logo="logo.js";
document.write("<scr"+"ipt src="+logo+"></scr"+"ipt>");
</script>

Hope that helps :)

Carl

Gregg
10-02-2002, 04:41 AM
Thank you Carl,

it was that simple. what I am learning here (slowly) is the logic to the language, and jsut having the command write itself makes sense, but not until you pointed it out.

Thank you again,

Gregg