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
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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.