473,715 Members | 5,945 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"parentObj is not defined" error when removing created elements

12 New Member
Hi everyone. I have some questions, which should be rather easy to reply, but as I am working on PHP, JavaScript, XML, CSS, Photoshop and other stuff at the same time, my head, which is about to explode, would be grateful for any answers :).

1) I have created a simple navigation system which loads local html documents on a main big DIV element in my page. Although greek language (iso-8859-7) is working outside that DIV, inside it i see question marks. My HTML files only contain <div>..More elements..</div>. I have tried calling complete HTML documents (with html, head, body etc elements) but no luck. Is that approach wrong? Any ideas why this happens?

2) I use JavaScript to dynamically generate gadgets on the sidebar of my page with the document.create Element() and SomeElement.app endChild() methods. Whatever element wasn't originally on the page though (the divs I create), gives a "parentObj is not defined" error when i remove it, but the result is ok. It seems like the document element content needs to be copied to the browser memory and be refreshed...

Expand|Select|Wrap|Line Numbers
  1. function addSidebarElement() {
  2.   var ni = document.getElementById('gadgets');
  3.   var numi = document.getElementById('theValue');
  4.   var num = (document.getElementById('theValue').value -1)+ 2;
  5.   numi.value = num;
  6.   var newdiv = document.createElement('div');
  7.   var divIdName = 'newgadget'+num;
  8.   newdiv.setAttribute('id',divIdName);
  9.   newdiv.setAttribute('style','display: none;');
  10.   newdiv.innerHTML="<h2 onclick=\"Effect.toggle('"+divIdName+"Content','blind')\">"+divIdName+"</h2><ul id=\""+divIdName+"Content\"><li><a href=\"#\">Fusce dui neque fringilla</a></li></ul><span onclick=\"removeElement(this);\">Remove Gadget</span>";
  11.   ni.appendChild(newdiv);
  12.  
  13.   Effect.SlideDown(divIdName);
  14. }
  15.  
  16. function removeElement(divObj) {
  17. var parentObj = document.getElementById('gadgets');
  18. var childObj=divObj.parentNode;
  19. var divId=childObj.getAttribute('id');
  20. Effect.SlideUp(divId);
  21.  
  22. setTimeout("parentObj.removeChild(childObj)",2000);
  23. }
Any explanations? I am worried that this problem is gonna make it worse after I add more stuff dynamically...
Sep 12 '07 #1
6 2559
acoder
16,027 Recognized Expert Moderator MVP
Changed the thread title to something more meaningful.

Does this error occur on the setTimeout?
Sep 13 '07 #2
newholborn
12 New Member
Probably not because it was the same before I added that line. I think it's line 17. It seems that the second function can't call any element by it's id. :/

And I can't change the topic title. (???)
Sep 13 '07 #3
dmjpro
2,476 Top Contributor
Look at your modified Code.
I did it.

Expand|Select|Wrap|Line Numbers
  1. var parentObj = null; //Defined here.
  2. function addSidebarElement() {
  3.   var ni = document.getElementById('gadgets');
  4.   var numi = document.getElementById('theValue');
  5.   var num = (document.getElementById('theValue').value -1)+ 2;
  6.   numi.value = num;
  7.   var newdiv = document.createElement('div');
  8.   var divIdName = 'newgadget'+num;
  9.   newdiv.setAttribute('id',divIdName);
  10.   newdiv.setAttribute('style','display: none;');
  11.   newdiv.innerHTML="<h2 onclick=\"Effect.toggle('"+divIdName+"Content','blind')\">"+divIdName+"</h2><ul id=\""+divIdName+"Content\"><li><a href=\"#\">Fusce dui neque fringilla</a></li></ul><span onclick=\"removeElement(this);\">Remove Gadget</span>";
  12.   ni.appendChild(newdiv);
  13.  
  14.   Effect.SlideDown(divIdName);
  15. }
  16.  
  17. function removeElement(divObj) {
  18. parentObj = document.getElementById('gadgets'); //Redefined here.
  19. var childObj=divObj.parentNode;
  20. var divId=childObj.getAttribute('id');
  21. Effect.SlideUp(divId);
  22.  
  23. setTimeout("parentObj.removeChild(childObj)",2000);
  24. }
Now test this, I think it will work.
Good Luck.


Kind regards,
Dmjpro.
Sep 13 '07 #4
newholborn
12 New Member
Thanks Dmjpro. Unfortunately, with this modification, the error remains, while the added element is not removed. :(
Sep 13 '07 #5
newholborn
12 New Member
Found it. I removed the scriptaculous effect and now no error, but unfortunately no effect.

The new code:

Expand|Select|Wrap|Line Numbers
  1. function removeElement(divObj) {
  2. var parentObj = document.getElementById('gadgets');
  3. var childObj=divObj.parentNode;
  4. var divId=childObj.getAttribute('id');
  5. //Effect.SlideUp(divId);
  6. parentObj.removeChild(childObj);
  7. //setTimeout("parentObj.removeChild(childObj)",2000);
  8. }
I'll keep you posted on the progress...

By the way, whats the difference of creating a scriptaculous effect with

Expand|Select|Wrap|Line Numbers
  1. new Effect.EffectName('divid');
and

Expand|Select|Wrap|Line Numbers
  1. Effect.EffectName('divid');
???
Sep 13 '07 #6
dmjpro
2,476 Top Contributor
You can do one more thing with my Code.
As parentObj defined outside you can define childObj as well.

Expand|Select|Wrap|Line Numbers
  1. var parentObj = null; //Defined here.
  2. var childObj = null; //Defined here.
  3. function addSidebarElement() {
  4.   var ni = document.getElementById('gadgets');
  5.   var numi = document.getElementById('theValue');
  6.   var num = (document.getElementById('theValue').value -1)+ 2;
  7.   numi.value = num;
  8.   var newdiv = document.createElement('div');
  9.   var divIdName = 'newgadget'+num;
  10.   newdiv.setAttribute('id',divIdName);
  11.   newdiv.setAttribute('style','display: none;');
  12.   newdiv.innerHTML="<h2 onclick=\"Effect.toggle('"+divIdName+"Content','blind')\">"+divIdName+"</h2><ul id=\""+divIdName+"Content\"><li><a href=\"#\">Fusce dui neque fringilla</a></li></ul><span onclick=\"removeElement(this);\">Remove Gadget</span>";
  13.   ni.appendChild(newdiv);
  14.  
  15.   Effect.SlideDown(divIdName);
  16. }
  17.  
  18. function removeElement(divObj) {
  19. parentObj = document.getElementById('gadgets'); //Redefined here.
  20. childObj=divObj.parentNode;
  21. var divId=childObj.getAttribute('id');
  22. Effect.SlideUp(divId);
  23.  
  24. setTimeout("parentObj.removeChild(childObj)",2000);
  25. }
Good Luck.

Kind regards,
Dmjpro.
Sep 14 '07 #7

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

Similar topics

2
5620
by: Liang | last post by:
Hi, I use "defined $r_libs->{$name}" to check first if a key exists in a hash table. But Perl gives a warning WHENEVER the key exists: "Use of uninitialized value". Would u please help to check the script, and let me know the reason? Thanks in advance. Liang
4
6445
by: Dmitry | last post by:
Hello, Sometimes on js code execution Mozilla 1.5 prints in JS concole the following error: "Error: fn is not defined" where "fn" is the function name surely defined _before_ the line that produces error. The fn body and error line both live in the same *.js file.
11
9847
by: MLH | last post by:
I copied the following code snippet from A97 HELP. Am getting an error at compile time suggesting there's a problem with the first line (compile error, user-defined type not defined). It is likely that I've left something out. Doesn't seem to like Dim dbs as Database - that's what's hi-lited after acknowledging the error. Can you see anything wrong with that syntax? Dim dbs As Database, rst As Recordset Dim rstEmployees As Recordset,...
6
1723
by: david | last post by:
When I compile a window form client for web service, there is error message as follows: Program 'D:\usr\winVBcontrol\WinClient4WebServiceFileCS\obj\Debug\WinClient4WebServiceFileCS.exe' does not have an entry point defined Notice: I create a solution (perhaps for VB). In the sulotion, I created win form clients for web service with VB in a window form VB project and they worked fine. Now the current one is developed in a C# project under...
10
1636
by: Eric G. Harrison | last post by:
We have a project with many other projects referenced (all of which are referenced at the project level and are included in the solution). Frequenly, if we make a change in project A (such as adding a property, or even simply changing a line of code), a form in project B will then show 10 or more "object such-and-such is not defined". To fix this problem we check out the form in project B and 90% of the time that fixes it (but nothing changes...
2
2061
by: Yannick Turgeon | last post by:
Hello, I'm using A97 (french version) on XP (english version). Since this afternoon, all the Access built-in french-equivalent function are generating a "Sub or Function not defined" error. An exemple: IIf(1=1,"bob","joe") is ok but it's french equivalent VraiFaux(1=1,"bob","joe") generates the error. It's not linked to the PC since other applications with this function
2
1682
by: Yarik | last post by:
Hello, I am not sure the subject of my post adequately describes the problem I am trying to solve, so I think a specific example would be helpful. Let's say there are XML descriptions of products like this one: <!-- File: Products.xml --> ... <Product id="p1">
3
4737
by: KelHemp | last post by:
I have compiled data from 13 tables, one for each month of the year that hold 45 fields each, and another for employee information, that holds 16 fields. The database is intended to record hours and special pay withholdings. I split up the report into First Half and Second Half, as the paper version we use currently does. My report First Half let me create control boxes for each field I wanted to include, however, when I try printing or...
2
11705
by: chenxinleo | last post by:
Hi, When i use some standard library functions and fields,which return char* type(like ctime in time.h, optarg in getopt.h)and do not have to be freed after calling,i always worry about memory leaking(thoug i konw i just donot have to).Then i look inside in time.h file(mingw) ,and i found notes say"These functions write to and return pointers to static buffers that may be overwritten by other function calls".So how is the"static buffers"...
0
8718
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,...
0
9196
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 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...
0
7973
agi2029
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...
0
5967
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4477
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...
0
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3175
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
2
2539
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2118
bsmnconsultancy
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...

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.