473,395 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Javascript Error comes and goes

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
May 15 '07 #1
2 1266
acoder
16,027 Expert Mod 8TB
You don't have an element with id "myTitle". Use a valid id.
May 15 '07 #2
Ok, now I have it (I was copying and pasting and visual studio changed the ID).
It is working fine like this:

<%@ 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>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />

</form>

<div>
<div id="myTitle" style="z-index:2; position: absolute; top: 30px; border-right: gray thin solid; border-top: gray thin solid; border-left: gray thin solid; border-bottom: gray thin solid; background-color: aqua;" > DHTML Animation </div>

<input id="DownButton" value="Move It Down!" style="z-index:1; position: absolute; top: 60px; width: 100px;" type="button" onclick="fr=0; move();"/>

<input id="Button1" value="Move It Up!" style="z-index:1; position: absolute; top: 60px; left: 150px; width: 100px;" type="button" onclick="fr=0; moveUp();"/>
</div>

<script type="text/javascript">

var x = new getObj('myTitle');
var topMemory = x.style.top;

function getObj(name)
{
if (document.getElementById)
{
this.obj = document.getElementById(name);
this.style = document.getElementById(name).style;
}
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>

</body>

</html>

But if I put my div inside the form it doesn't work in IE7 (but it does in Firefox!)

What's this!?!

Thanks,

G
May 18 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: fig000 | last post by:
Hi, I'm relatively new to Javascript so please bear with me on what might sound like silly questions. This is what I want to do: I'm working in classic asp (I have to for this project). I...
5
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one...
3
by: Java script Dude | last post by:
I have still yet to see a JavaScript Editor that comes close to reading a good JS book, learing it and using it with a text editor. Anyway, here my recipe for build successfull DHTML...
18
by: marcokrechting | last post by:
Hi All, I have a rather complicated problem. I use following function to display a hyperlink: a="<"+"a href='"; b3="<"+"a href='http://nww."; L="</"+'a><br>'; function...
5
by: Paul Krasucki | last post by:
This is for a search page that takes parameters on one page, processes the query, and displays them on another page. I've got a javascript popup window on a button click event. When the user...
9
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work...
5
by: rodchar | last post by:
hey all, in my page load i'm attaching a javascript confirm message to my save button. my problem is i have some client side validation which uses a Custom Validator web control and when i make...
34
by: electrician | last post by:
Perl has it, Basic has it, Fortran has it. What is so difficult about creating a goto command for JavaScript. Just set up a label and say go to it.
5
by: mkhines | last post by:
Hello Javascript Experts (of which I am not ! ) -- I'm trying to utilize a javascript I found on the web that allows a user to select a time of day from a simple control. The script works just...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.