Hi All,
Don't know where to put the post as it involves javascript and ASP.NET pages, so I'll just put it here.
I have a very simple aspx page and and a couple of simple javascript functions to move elements around the page (up and down).
If I execute js functions from within the form I got Microsoft JScript runtime error: Object required, If I do that from outside the form everything works the way it's supposed to.
Any Idea?
Here is the page (bold where I get the error):
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">
var topMemory=0;
function getObj(name)
{
if (document.getElementById)
{
this.obj = document.getElementById(name);
this.style = document.getElementById(name).style;
} <--ERROR HERE
else if (document.all)
{
this.obj = document.all[name];
this.style = document.all[name].style;
}
else if (document.layers)
{
this.obj = document.layers[name];
this.style = document.layers[name];
}
}
function move()
{
var x = new getObj('myTitle');
x.style.position = 'absolute';
if (100 > fr++)
{
x.style.top = parseInt(topMemory) + 2*fr;
if (100 == fr)
{
topMemory = x.style.top;
}
setTimeout('move()', 50);
}
}
function moveUp()
{
var x = new getObj('myTitle');
x.style.position = 'absolute';
if ( 100 > fr++)
{
x.style.top = parseInt(topMemory) - 2*fr;
if (100 == fr)
{
topMemory = x.style.top;
}
setTimeout('moveUp()', 50);
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1 id="H1_1" style="top: 0;" > DHTML Animation </h1>
<input id="Button2" value="Move It Down!" style="position: absolute; top: 60px;" type="button" onclick="fr=0; move();"/>
<input id="Button3" value="Move It Up!" style="position: absolute; top: 60px;left: 150px;" type="button" onclick="fr=0; moveUp();"/>
</div>
</form>
</body>
</html>
Cheers,
Giovanni