Click to See Complete Forum and Search --> : object required


zuzupus
08-13-2003, 03:25 AM
hi,
i got problem while running this file as javascript error as object required dont no why hopefull help me out
http://172.16.0.100/scripts/test.phtml

my code is mix of PHP and javascript



<? $dir = './'; require($dir.'lib.php'); get_session(); ?>

<html>
<head>

<title>Upload</title>
<link rel="stylesheet" type="text/css" href="../styles/styles.css" />
<? if ($session->active != $active || $active) { ?>
<script language="JavaScript" type="text/javascript">
<!--
<?
if ($active && $mayRead) {
list($info, $html_file) = once_query_array("SELECT info, html_file FROM t_directories WHERE sys_pk = $active");
if (is_true($info)) {
?>
parent.frames['content'].location.replace('../htm/<?=addslashes($html_file ? "infos/$html_file" : "empty.htm") ?>');
<? } else { ?>
parent.frames['content'].location.replace('filelist.phtml?type=<?=(($rights == 2) ? 1 : 0) ?>&tree=<?=$active ?>');
<? } } else { ?>
parent.frames['content'].location.replace('blank.phtml');
<? } ?>
function saveScrollPosition() {
var scrollY;
if (window.innerHeight)
{
scrollY = window.pageYOffset
}
if (document.all)
if (document.documentElement && document.documentElement.scrollTop)
{
scrollY = document.documentElement.scrollTop;
}
else if (document.body)
{
scrollY = document.body.scrollTop;
}
else
scrollY = window.pageYOffset;
parent.scrollY = scrollY;
}
function scrollWindow() {
window.scrollTo(0, parent.scrollY);
}
// -->
</script>
<? } ?>
<?
$session->active = $active;
?>
</head>
<body class="gray">
<table border="0" cellpadding="0" cellspacing="0" height="95%" width="100%">
<tr>
<td valign="top" align="left">

<?
function showTree($id, $level) {
global $tree, $session, $active;
$var = is_array($tree[$id]) ? $tree[$id] : array();
foreach($var as $pk => $name) {
if ($name[0] == chr(1)) { $new = true; $name = substr($name, 1); } else $new = false;
if ($name[0] == '+' || $name[0] == '-')
$link = 'href="'.htmlentities("test.phtml?flip=$pk&close=".($session->open[$pk] ? 1 : 0)).'"';
else
$link = 'href="'.htmlentities("test.phtml?active=$pk").'"';
?>

<p class="h<?=(($level > 4) ? 7 : ($level+3)) ?>"><?=str_repeat('&nbsp;', $level*3) ?><a onclick="saveScrollPosition();" class="h<?=(($level > 4) ? 7 : ($level+3)) ?>" <?=$link ?>><?=(($active == $pk || $new) ? '<span class="'.($active == $pk ? 'white' : 'newfiles').'">' : '') ?><?=htmlentities($name) ?><?=(($active == $pk || $new) ? '</span>' : '') ?></a></p>

<?
if ($session->open[$pk])
showTree($pk, $level+1);
}
}
showTree(0, 0);
?>
</td>
</tr>


</table>
<script language="JavaScript" type="text/javascript">
<!--
setTimeout("scrollWindow();", 20);
// -->
</script>
</body>
</html>






thanks in advance

Caz
08-13-2003, 06:47 AM
If the error occurs at "line 0 character 0" then most likely it's the setTimeout that generates the error.

The command line inside the setTimeout is not considered part of your script. Thus you don't get the error at the line where the setTimeout is set, but instead at line 0 character 0.

I sometimes get similar errors, that's when there's something wrong with the command line inside the setTimeout (mispelling or case error).

In your case, it seems that the spelling and case are correct, so maybe it's just PHP (not-)adding elements that make your script wrong?

Have you checked the JS source after PHP processing?
I'd also try a scrollWindow test outside of the setTimeout.

If there's an error somewhere in the code, it should then make it easier to detect by indicating a line number.

zuzupus
08-13-2003, 07:37 AM
thanks alot anyhow i modify the code and try to remove onload form javascript error but when i click on some trees on left frame it jumps up and when i click on any tree on left frame i got javascript error dont no why


function saveScrollPosition()
{

var scrollY;
if (document.all)
if (window.innerHeight)
{
scrollY = window.pageYOffset
}
else if (document.documentElement && document.documentElement.scrollTop)
{
scrollY = document.documentElement.scrollTop
}
else if (document.body)
{
scrollY = document.body.scrollTop
}
else
scrollY = window.pageYOffset;
parent.scrollY = scrollY;

temp = setTimeout('scrollWindow()',20);
}
function scrollWindow() {
window.scrollTo(0, parent.scrollY);
}


thanks its appreciable