Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Div Not Scrolling in Firefox

Status
Not open for further replies.

Clanger67

Programmer
Mar 28, 2002
28
GB
I have created a Div that displays help text when a user clicks on a textbox, checkbox, radio button etc. The Div then scrolls down the left side of the page, keeping it at the top.

It works fine in IE 6 and 7, but I cannot get it to work in Firefox. It just sits there.

I have posted the JS code below that I am using.

Code:
//This to enable the floating to work in all browsers, especially IE which has its own syntax eg: scrollTop
//Checks to see if the document is standards compliant
function ieTrueBody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function setVariables()
{
	if (navigator.appName == "Netscape")
	{
		horz=".left";
		vert=".top";
		docStyle="document.";
		styleDoc="";
		offsetX="window.pageXOffset";
		offsetY="window.pageYOffset";
	}
	else
	{
		horz=".pixelLeft";
		vert=".pixelTop";
		docStyle="";
		styleDoc=".style";
		offsetX="document.body.scrollLeft";
		offsetY="document.body.scrollTop";
   }
}
function checkLocation()
{
	objectXY="divHelp";
	var availableX=eval(3);
//	var availableY=eval(96);
	var availableY=eval(0);
	var currentX=eval(offsetX);
	var currentY=eval(offsetY);
	if (currentY > 96)
	{	currentY -= 96;
	}
	else
	{	if (currentY = 0)//if (currentY != 0)
		{	availableY=eval(96 - currentY);
		}
	}

	x=availableX+currentX;
//	y=availableY+currentY;
	y=currentY;
	evalMove();
	setTimeout("checkLocation()",10);
}

function evalMove()
{
		eval(docStyle + objectXY + styleDoc + horz + "=" + x);
		eval(docStyle + objectXY + styleDoc + vert + "=" + y);
}
setVariables();
checkLocation();


Any help would be much appreciated.

David
 
Install Firebug (the extension) for Firefox. Open up the console and see if there are any javascript errors shown.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Wow, browser sniffing AND eval abuse....

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
 
Jeff

Thanks for the tip about Firebug. I have installed it and it points to the following line as being the problem.

Code:
eval(docStyle + objectXY + styleDoc + horz + "=" + x);

This is the error message that Firebug is giving
Code:
[red]document.divHelp has no properties[/red]
[blue]valMove()floathelp.js (line 54)[/blue]
[blue]checkLocation()floathelp.js (line 48)[/blue]
[green] eval(docStyle + objectXY + styleDoc + horz + "=" + x);[/green]
Kaht I am not a java programmer, I have had a 3 day course and been asked to try and get something working. If you have any useful tips on what to replace the above line of code with it would be much appreciated.

David
 
Hi

Personally I find this problem challenging and I would give it a look. But I have no time to build the HTML document around it.

Anyway, what kaht wrote in an educated manner, that code is deprecated and stupid.

If you still would like our help for that, please post the HTML ( and maybe CSS too if is relevant ). Or give us the URL of the page if it can be accessed online.

Feherke.
 
I wonder whether your use of variables and their (lack of clearly defined) scope is at the heart of the problem.

That eval is using 5 variables: [docStyle, objectXY, styleDoc, horiz, x] and none of those variables are global (they are defined/set in one function, but not made available outside that function.

Try declaring these 5 variables (at least) globally and see how that changes things. Try this just before you run setVariables():
Code:
var docStyle, objectXY, styleDoc, horiz, x;
This is not a very nice way to complete this kind of problem (leaving global variables in the document etc), but it's a stepping stone (hopefully) to a better solution.

As kaht points out, the use of eval() is not really looked upon favourably (there is a time and a place for it's use, but that is very very seldom). Once this problem is resolved in the first instance, you might want to revisit the solutoion (in a different thread) and refactor it to make it better.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top