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!

NN4 Section of Script not working :)

Status
Not open for further replies.

JProg

Programmer
Apr 4, 2002
88
JP
Hi Everyone,

I have a script that is designed to dynamically position page elements. It is working very well in IE6 and NN7. However I have tried the script in NN4 and it is not working at all. I have not yet had the opportunity to test this script on IE4! Please see the code below, the largely commented section toward the bottom of the script is where the NN4 commands are located. If you can help me with working out what is wrong with the way I have written this script I will be greatly appreciative.
Code:
<html>
<title> Simple Element Positioning Script </title>
<head>
<style type="text/css">
#car
{
	position:	absolute;
}
</style>
<script language="javascript" type="text/javascript">
// <!--
// Set an indicator variable to determine DOM supported by current browser.

var domIndicator = 0;		

if(document.getElementById)
{
	// IE5+ or NS6+ Browser detected.
	domIndicator = 1;
}
else
if(document.all)
{
	// IE4 Browser detected.
	domIndicator = 2;
}
else
if(document.layers)
{
	// NS4 Browser detected.
	domIndicator = 3;
}

function posElem(elementID, xPos, yPos)
{
	if(domIndicator == 1)
	{
		var element = document.getElementById(elementID);
		element.style.left = xPos;
		element.style.top = yPos;
	}
	else
	if(domIndicator == 2)
	{
		var element = document.all.item(elementID);
		element.style.posLeft = xPos;
		element.style.posTop = yPos;
	}
	else
	if(domIndicator == 3)
	{
		//When run in NN4 the following error message is produced regardless of 
		//which of the following techniques is used!

		//JavaScript Error: file:/E|/Web Development/SimplePositioner.htm, line 52:
		//**** document.elementID has no properties. ******

		//document.layers[elementID].left = xPos;
		//document.layers[elementID].top = yPos;

		//document.elementID.left = xPos;
		//document.elementID.top = yPos;

		//var element = document.layers[elementID];
		//element.left = xPos;
		//element.top = yPos;
	}
}

// -->
</script>
</head>
<body>
<img id="car" src="car.jpg">
	<script type="text/javascript">
		posElem('car', 100, 100);
	</script>
</body>
</html>
Also if you can see anything wrong with the way the IE4 section is coded can you please point it out, as I am not in a position to check this section (I don't have IE4 - I guess not many people do). Thanks heaps for your assistance.

Regards

Davo
 
else
if(domIndicator == 2)
{


is that a typo?
else if
is the correct format...

Known is handfull, Unknown is worldfull
 
vbkris said:
else
if(domIndicator == 2)
{

is that a typo?
else if
is the correct format...

You can have as much or as little white-space between the "else" and the "if" as you like - as long as you have at least one character of white.space. Therefore, any of the following would be acceptable:

Code:
else if

Code:
else      if

Code:
else



if

Code:
else





                                if

I think you get the idea ;o)

Dan

 
Hey Guys,

The whole code format debate is none existant as far as I can tell. Basically unless you have some kind of nerd affliction, you may as well do as you please which pretty much means using whatever approach works! As Dan pointed out there is definitely more than one way of getting the job done.

Regards

Davo
 
dan, i thought it was an enter rather that a white space...

Known is handfull, Unknown is worldfull
 
now i am confused,

isnt: (else if without whitespace)
else if

different from: (thats an if inside an else)
else
if


Known is handfull, Unknown is worldfull
 
actually no. the only difference would be if there were no space between them (space also meaning new line) - in which case it would be wrong sintactically


--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top