RIRedinPA Posted May 21, 2009 Share Posted May 21, 2009 I have this in my code: <div id="tablebox"> <?php if ($_SESSION['view'] == "e" || $_SESSION['view'] == "") { ?> <div id="etable" style="display: block;"><?php print $etable; ?></div> <div id="atable" style="display: none;"><?php print $atable; ?></div> <?php } else { ?> <div id="etable" style="display: none;"><?php print $etable; ?></div> <div id="atable" style="display: block;"><?php print $atable; ?></div> <?php } ?> </div> $etable and $atable are tables showing production schedule data. I have a bunch of Javascript/AJAX/PHP to add, delete, update the contents of the table. Everything was working fine but now I keep getting error messages saying atable doesn't exist, which is false as it does: Error: document.getElementById("atable") is null Source File: http://xxxxxx.xxxxxx.com/pwc/js/pwcjs.js Line: 375 This particular error comes from my Javascript used to toggle table views: function toggleview() { if (document.getElementById('etable').style.display == "block") { document.getElementById('etable').style.display = "none"; document.getElementById('atable').style.display = "block"; var view = 'a'; } else { document.getElementById('atable').style.display = "none"; document.getElementById('etable').style.display = "block"; var view = 'e'; } //change view var xmlHttp = checkajax(); xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { //alert(xmlHttp.responseText); //I'm using this to set a PHP session variable so I can maintain the user's view when they do other things like add or delete a row } } xmlHttp.open("GET","lib/changeview.php?view=" + view, true); xmlHttp.send(null); } It happens on pretty much every call to that div, which I guess is good news since its a universal problem and not some random thing. What am I doing wrong here that JS can't see the div? Link to comment https://forums.phpfreaks.com/topic/159126-javascript-does-not-recognize-div/ Share on other sites More sharing options...
Ken2k7 Posted May 21, 2009 Share Posted May 21, 2009 Where did you put that JavaScript code? Link to comment https://forums.phpfreaks.com/topic/159126-javascript-does-not-recognize-div/#findComment-839205 Share on other sites More sharing options...
RIRedinPA Posted May 21, 2009 Author Share Posted May 21, 2009 Where did you put that JavaScript code? Hi I never posted it because the powers that be decided collapsing columns wasn't necessary. Thanks again for the help offer though. Link to comment https://forums.phpfreaks.com/topic/159126-javascript-does-not-recognize-div/#findComment-839212 Share on other sites More sharing options...
RIRedinPA Posted May 21, 2009 Author Share Posted May 21, 2009 it can't be the reason, I flipped the order of the divs and now it works... <div id="tablebox"> <?php if ($_SESSION['view'] == "e" || $_SESSION['view'] == "") { ?> <div id="atable" style="display: none;"><?php print $atable; ?></div> <div id="etable" style="display: block;"><?php print $etable; ?></div> <?php } else { ?> <div id="atable" style="display: block;"><?php print $atable; ?></div> <div id="etable" style="display: none;"><?php print $etable; ?></div> <?php } ?> </div> Why would that matter? Link to comment https://forums.phpfreaks.com/topic/159126-javascript-does-not-recognize-div/#findComment-839213 Share on other sites More sharing options...
Ken2k7 Posted May 21, 2009 Share Posted May 21, 2009 I would imagine it works before too. Link to comment https://forums.phpfreaks.com/topic/159126-javascript-does-not-recognize-div/#findComment-839223 Share on other sites More sharing options...
roopurt18 Posted May 21, 2009 Share Posted May 21, 2009 1) Run your markup through a validator. 2) Run your JavaScript through JSLint. Link to comment https://forums.phpfreaks.com/topic/159126-javascript-does-not-recognize-div/#findComment-839417 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.