Click to See Complete Forum and Search --> : using a VAR variable in html table


bsharris
08-07-2003, 12:14 PM
I am passing to this html page, some variables to include font size and font name.
in the onload - I parse out the Global variable num - equal to the font size , in this test, a 2.

how can I use that variable in my html table, to display a cell with a font size of 2 (num)





<script language="JavaScript">
var num = ' ';

function load() {

var str = location.search
var pos = str.indexOf("&");
var pos1 = str.indexOf("?");

num = str.substring(pos1 + 10, pos-pos1);


}
</script>
</head>
<body bgcolor="#FFFFFF" onLoad="load()">
<table>
<tr>
<td> <font size="#num">testing font sizes</font></td>
</tr>
</table>

Exuro
08-07-2003, 03:25 PM
Okay, I edited the code a bit... First off, IE likes to change characters such as & to an escaped form starting with a %. This is what the %26 is in the indexOf for pos. However, other browsers don't do this. So, if it doesn't find a %26 then it looks for an &. I also added some stuff so that if there is no search query, or the user is not using JavaScript, the page still displays with the default font size. By the way, the query I used when testing this was:
?aaaaaaaa=9&f=2
Anyway, here's the code:

<body bgcolor="#FFFFFF">
<table border="1">
<tr>
<script type="text/javascript">
<!--
var str = location.search
var pos = str.indexOf("%26");
if (pos==-1)
{pos = str.indexOf("&");}
var pos1 = str.indexOf("?");
var num;
if (str.length!=0) {
num = str.substring(pos1 + 10, pos-pos1);alert(str)
document.write('<td> <font size="'+num+'">testing font sizes</font></td>');
}
else {
document.write('<td>testing font sizes</td>');
}
//-->
</script>
<noscript><td>testing font sizes</td></noscript>
</tr>
</table>