I have adapted code from http://dunnbypaul.net/js_mouse/
I want to use a button to create new draggable divs but i keep getting error "is null or not an object"
heres the code - <html>
-
<head>
-
<title>Drag and drop module</title>
-
<style type="text/css">
-
#canvas {
-
margin:auto;
-
padding:0px;
-
position: absolute;
-
background-color:grey;
-
border:dashed gray 1px;
-
top: 5px;
-
margin:auto;
-
padding:0px;
-
width:100%;
-
height:400px;
-
float:left;
-
font-size: 8px;
-
font-family:Arial, Helvetica, sans-serif;
-
overflow: hidden;
-
}
-
#controls {
-
margin:auto;
-
padding:10px;
-
position: absolute;
-
width:100%;
-
top:415px;
-
float:left;
-
background: grey;
-
border:dashed black 1px;
-
height: 150px;
-
}
-
#newObject {
-
position: absolute;
-
left: 10px;
-
top: 10px;
-
background-color:green;
-
border:solid gray 1px;
-
margin:10px;
-
padding:4px;
-
width:50px;
-
height:50px;
-
float:left;
-
zIndex:1;
-
cursor:pointer;
-
font-size: 8px;
-
font-family:Arial, Helvetica, sans-serif;
-
}
-
</style>
-
<script type = "text/javascript">
-
function createObject (){
-
cv = document.getElementById("canvas");
-
var newObject = document.createElement('div');
-
newObject.Class = "newObject";
-
newObject.id = "newObject";
-
cv.appendChild(newObject);
-
newObject.onmousedown=grab(this);
-
-
}
-
-
var mousex = 0;
-
var mousey = 0;
-
var grabx = 0;
-
var graby = 0;
-
var orix = 0;
-
var oriy = 0;
-
var elex = 0;
-
var eley = 0;
-
var algor = 0;
-
-
var dragobj = null;
-
-
function falsefunc() { return false; } // used to block cascading events
-
-
function init()
-
{
-
document.onmousemove = update; // update(event) implied on NS, update(null) implied on IE
-
update();
-
}
-
-
function getMouseXY(e) // works on IE6,FF,Moz,Opera7
-
{
-
if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)
-
-
if (e)
-
{
-
if (e.pageX || e.pageY)
-
{ // this doesn't work on IE6!! (works on FF,Moz,Opera7)
-
mousex = e.pageX;
-
mousey = e.pageY;
-
algor = '[e.pageX]';
-
if (e.clientX || e.clientY) algor += ' [e.clientX] '
-
}
-
else if (e.clientX || e.clientY)
-
{ // works on IE6,FF,Moz,Opera7
-
mousex = e.clientX + document.body.scrollLeft;
-
mousey = e.clientY + document.body.scrollTop;
-
algor = '[e.clientX]';
-
if (e.pageX || e.pageY) algor += ' [e.pageX] '
-
}
-
}
-
}
-
-
function update(e)
-
{
-
getMouseXY(e); // NS is passing (event), while IE is passing (null)
-
-
document.getElementById('xpos').value = elex;
-
document.getElementById('ypos').value = eley;
-
document.getElementById('object').value = dragobj ? (dragobj.id ? dragobj.id : 'unnamed object') : '(null)';
-
}
-
-
function grab(context)
-
{
-
document.onmousedown = falsefunc; // in NS this prevents cascading of events, thus disabling text selection
-
dragobj = context;
-
dragobj.newObject.zIndex = 10; // move it to the top
-
document.onmousemove = drag;
-
document.onmouseup = drop;
-
grabx = mousex;
-
graby = mousey;
-
elex = orix = dragobj.offsetLeft;
-
eley = oriy = dragobj.offsetTop;
-
update();
-
}
-
-
function drag(e) // parameter passing is important for NS family
-
{
-
if (dragobj)
-
{
-
elex = orix + (mousex-grabx);
-
eley = oriy + (mousey-graby);
-
dragobj.newObject.position = "absolute";
-
dragobj.newObject.left = (elex).toString(10) + 'px';
-
dragobj.newObject.top = (eley).toString(10) + 'px';
-
}
-
update(e);
-
return false; // in IE this prevents cascading of events, thus text selection is disabled
-
}
-
-
function drop()
-
{
-
if (dragobj)
-
{
-
dragobj.style.zIndex = 0;
-
dragobj = null;
-
}
-
update();
-
document.onmousemove = update;
-
document.onmouseup = null;
-
document.onmousedown = null; // re-enables text selection on NS
-
}
-
-
</script>
-
</head>
-
<body onload="init();">
-
<div id = "canvas">
-
</div>
-
<div id = "controls">
-
<input type = "button" value = "New Object" onClick = "createObject()">
-
<input type = "text" value = "" name = "xpos" id = "xpos">
-
<input type = "text" value = "" name = "ypos" id = "ypos">
-
<input type = "text" value = "" name = "object" id = "object">
-
-
</div>
-
</body>
-
</html>
6 4943
sorry just to be a little clearer.
Error:
Line: 116
Char: 3
error: 'dragobj.newObj ect' is null or not an object
code:0
acoder 16,027
Recognized Expert Moderator MVP
"If you can solve this your a genius!!" is a brilliant title :D, but doesn't really describe the problem, so I've changed it.
Re. your problem: dragobj.newObje ct is incorrect. Replace newObject with style. See if that makes a difference.
yeah I have already tried that. I think the problem lies in the createObject function. Seems to be a problem assigning the onmousedown event.
acoder 16,027
Recognized Expert Moderator MVP
Yeah, that should be: - newObject.onmousedown=function(){grab(this);}
Yeah, that should be: - newObject.onmousedown=function(){grab(this);}
Has anyone every told you you're some pup! :)
Thanks... you don't know how much that has helped
acoder 16,027
Recognized Expert Moderator MVP Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Don Vaillancourt |
last post by:
What's going on with Javascript.
At the beginning there was the "undefined" value which represented an
object which really didn't exist then came the null keyword. But
yesterday I stumbled across "null" string.
I know that I will get an "undefined" when I try to retrieve something
from the DOM which doesn't exist.
I have used null...
|
by: Lauchlan M |
last post by:
Hi.
Usin ASP.NET, getting an "Object reference not set to an instance of an
object" error.
In my login.aspx page I have:
string arrUserRoles = new string {"UserRole"};
Context.Items.Add("UserRoles", arrUserRoles);
Context.User = new
|
by: Karel Vandenhove |
last post by:
Hi,
I get an error "cannot apply indexing with to an expression of type
object" when I try to compile the code below.
SSLScannerManager is a COM component. (Used to access fingerprint
scanners and developed by neurotechnologija)
How does one get an array from a com component?
|
by: Christian Hvid |
last post by:
What is the easiest way to get the "row object" or "item object" when a
datagrid is clicked?
I have web form with a datagrid. And I have an array of something called
BlogEntry that I bind to the grid like this:
private void Page_Load(object sender, System.EventArgs e)
{
BlogEntry entries = DataLayer.GetAllBlogEntries();...
|
by: Joe Van Dyk |
last post by:
When you delete a pointer, you should set it to NULL, right?
Joe
| |
by: louie.hutzel |
last post by:
This JUST started happening, I don't remember changing any code:
When I click the submit button on my form, stuff is supposed to happen
(which it does correctly) and a result message is posted back to the
same page at the top of my form alerting the user that their request
has been approved or denied. However, the end result is an error...
|
by: JHNielson |
last post by:
I have a simple question, but I can't seem to find the answer.
I have this code to count the number of records that pass through a set of processes:
It counts how many records go through INPUT, VALIDATED, ERRORS
This is the code to get the numbers:
Function Val_Message()
|
by: =?Utf-8?B?QmFkaXM=?= |
last post by:
I'm doing a server side automation(I know it's bad but..) and its working
fine locally and when accessing it from a remote machine using web browser is
was giving me this error"Retrieving the COM class factory for component with
CLSID
{000209FF-0000-0000-C000-000000000046} failed due to the following error:
80070005". so I configured the...
|
by: piyumi80 |
last post by:
hi,
i wrote the following code to get a specific data row from the data set.but it generates the
"Object reference not set to an instance of an object.".....error
private void showClientListForUser()
{
string fkeys = new string;
fkeys = txtUserName.Text;
fkeys = txtUserCompanyNumber.Text;
|
by: RMWChaos |
last post by:
I am working on a script to create and remove DOM elements, and I want to make it as efficient as possible (no redundancies). Because DOM elements each have their own set of attributes, the function variable list is quite long, and each type of element may not use some of the variables. As a placeholder, I use "null" when there is no value, but...
|
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...
| |
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. ...
|
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...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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...
|
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...
| |
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |