...

View Full Version : Putting variable in HTML



florida
12-20-2002, 05:01 PM
Need to put a variable to substitute HTML data. Is it possible??

Here the HTML that I have which is already part of a Javascript:
<script>

//Javascript stuff etc...
<table bgcolor="#00ff00" border=0 cellpadding="0" cellspacing="0" width="100%" height="100%"
align="left"><tr><td><a href="http://mypath/home.html">myurl</a></td></tr></table>;
</script>
How can I do this??

var test = "<table bgcolor="#00ff00" border=0 cellpadding="0" cellspacing="0" width="100%"
height="100%" align="left"><tr><td>"


Here is how I want this variable to work.
test<a href="http://mypath/home.html">myurl</a></td></tr></table>;

ShriekForth
12-20-2002, 06:23 PM
Use can use the writeln().
Pass it a variable, or string, and it will write it out in the document where you call it... So this script



<body>
<script>
myurl = 'http://mypath/home.html'
test ='<table bgcolor="#00ff00" border=0 cellpadding="0" cellspacing="0" width="100%" height="100%" align="left"><tr><td><a href="' + myurl + '">myurl</a></td></tr></table>';
document.writeln(test);
</script>
</body>

would generate a green cell with the link in it. I also added a second variable just to see how that works. Make sure you don't get the ' and the " mixed up, or it will not parse correctly.

ShriekForth



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum