Jump to content

Javascript does not recognize div


RIRedinPA

Recommended Posts

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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.