Question : I'm trying to set an attribute to a declare varible

var test = "Hello World";
                       
cell1.setAttribute('onmouseover','alert(test)');

cell 1 is declared properly, i just cant get the code above to work.  If I remove the single quotes around the alert it does't working when I mouse over, it just execute immediately.

Answer : I'm trying to set an attribute to a declare varible

set test as global var :

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
<html><head>
<script  language="javascript">
var test = "Hello World"; //global var
	function init() {
		cell1 = document.getElementsByTagName("td")[0];
		cell1.setAttribute('onmouseover','alert(test)');
	}
</script>
</head>
<body onload="init();">
<table width="320" height="200" border="2" bordercolor="#000000">
<tr><td></td></tr>
</table>
</body></html>
Random Solutions  
 
programming4us programming4us