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="Defau lt.aspx.cs" Inherits="_Defa ult" %>
<!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>Untitl ed Page</title>
<script type="text/javascript" language="javas cript">
var topMemory=0;
function getObj(name)
{
if (document.getEl ementById)
{
this.obj = document.getEle mentById(name);
this.style = document.getEle mentById(name). style; } <--ERROR HERE
else if (document.all)
{
this.obj = document.all[name];
this.style = document.all[name].style;
}
else if (document.layer s)
{
this.obj = document.layers[name];
this.style = document.layers[name];
}
}
function move()
{
var x = new getObj('myTitle ');
x.style.positio n = 'absolute';
if (100 > fr++)
{
x.style.top = parseInt(topMem ory) + 2*fr;
if (100 == fr)
{
topMemory = x.style.top;
}
setTimeout('mov e()', 50);
}
}
function moveUp()
{
var x = new getObj('myTitle ');
x.style.positio n = 'absolute';
if ( 100 > fr++)
{
x.style.top = parseInt(topMem ory) - 2*fr;
if (100 == fr)
{
topMemory = x.style.top;
}
setTimeout('mov eUp()', 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
2 1283 acoder 16,027
Recognized Expert Moderator MVP
You don't have an element with id "myTitle". Use a valid id.
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="Defau lt.aspx.cs" Inherits="_Defa ult" %>
<!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>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptMana ger ID="ScriptManag er1" 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.getEl ementById)
{
this.obj = document.getEle mentById(name);
this.style = document.getEle mentById(name). style;
}
else if (document.all)
{
this.obj = document.all[name];
this.style = document.all[name].style;
}
else if (document.layer s)
{
this.obj = document.layers[name];
this.style = document.layers[name];
}
}
function move()
{
var x = new getObj('myTitle ');
x.style.positio n = 'absolute';
if ( 100 > fr++)
{
x.style.top = parseInt(topMem ory) + 2*fr;
if (100 == fr)
{
topMemory = x.style.top;
}
setTimeout('mov e()', 50);
}
}
function moveUp()
{
var x = new getObj('myTitle ');
x.style.positio n = 'absolute';
if ( 100 > fr++)
{
x.style.top = parseInt(topMem ory) - 2*fr;
if (100 == fr)
{
topMemory = x.style.top;
}
setTimeout('mov eUp()', 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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 need
to:
1. Click a submit button on an asp page, calling another page
that saves the contents of that form to a database and then displays
|
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 function to
verify the name fields, age, email and gender.
My question is: if I create a function for each field like the code
below, what would be the best way to organize the functions and call
them? Would I need one main function and place...
|
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 Applications:
If you want to support only M$ IE stop here and do the following:
1) Install blindfold
2) Repeat the phrase - I love my cage :p
Buy the Book: Buy O'Reilly's JavaScript The Definitive Guide
|
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 h(a){document.writeln(a)}
|
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
clicks the button, the popup window opens, and the parent page goes on with
the query. No problem there. The problems comes in when one of my
validator's throws an error, then naturally the page does not post back
waiting for the page to valid. ...
| |
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 fine from a
link.
The button does bring up the popup window, but when I press the links on the
page, it doesn't return or close the window.
****************************************************************************
|
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 the validation go off and hit save, it
allows me to postback with the error. Am i doing something wrong?
thanks,
rodchar
|
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.
|
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 fine in Internet Explorer (7) but doesn't work in Firefox when I
use it in my form. Firefox gives me an error (using firebug) that
says: "variablename" is not defined) where variablename is the
The odd thing about this is that the example that...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |