1 Replies - 430 Views - Last Post: 11 January 2013 - 05:04 AM

#1 njgmoorman  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 02-October 12

Trying to reference a table but null/undefined

Posted 11 January 2013 - 04:47 AM

Hi, I'm trying to set a variable that references a <table> tag using getElementById, but the variable is coming up in firebug as undefined in safari and null in Firefox.
Here's the JS:
var i, winloss, table, hw, mines, tdCounter, trCounter, tdClass;
// radios = document.getElementById("form").childNodes;
//table = document.getElementById("game");
var difficulty = "";
i=0;
winloss="";
setTimeout(table = document.getElementById("game"), 1000);


And the HTML:
<!DOCTYPE HTML>
<html>
<head>
	<title>Minesweeper</title>
	<script src="minesweeper.js" type="text/javascript"></script>
	<link rel="stylesheet" href="minesweeper.css" type="text/css" />
</head>
<body>
	<div>
		<form id="form">
			<input type="radio" name="radio" value="1" onclick="clearTable();newGame(1);" /><label> - BEGINNER</label>
			<input type="radio" name="radio" value="2" onclick="clearTable();newGame(2);" /><label> - EASY</label>
			<input type="radio" name="radio" value="3" onclick="clearTable();newGame(3);" /><label> - MEDIUM</label>
			<input type="radio" name="radio" value="4" onclick="clearTable();newGame(4);" /><label> - HARD</label>
			<input type="radio" name="radio" value="5" onclick="clearTable();newGame(5);" /><label> - EXPERT</label>
		</form>
	</div>
	<div id="div2">
		<table id="game">
		</table>
	</div>
</body>
</html>


Thanks for any help you can offer!

Is This A Good Question/Topic? 0
  • +

Replies To: Trying to reference a table but null/undefined

#2 e_i_pi  Icon User is online

  • = -1
  • member icon

Reputation: 793
  • View blog
  • Posts: 1,681
  • Joined: 30-January 09

Re: Trying to reference a table but null/undefined

Posted 11 January 2013 - 05:04 AM

setTimeout() expects the first argument to be a function AFAIK. So your line 7 should probably read this:
setTimeout(function() {table = document.getElementById("game")}, 1000);


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1