473,395 Members | 1,568 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.

newbie: removeChild() on table does nothing

Hello,
On index.html page I have a table with id="property_fields".

<table id="property_fields" name="property_fields" border="0">

It contains set of rows with the following IDs:

var propertyRows = new Array(
"region_row", "town_row", "district_row", "address_row", "house_row", "floor_no_row", "rooms_row", "floors_row", "area_row", "year_built_row",
"ownership_row", "standard_row", "garrage_row", "parking_row", "kitchen_row", "balcony_row", "gas_row", "media_row", "equipment_row", "guard_row",
"building_type_row", "picture1_row", "picture2_row", "picture3_row", "property_remarks_row"
);

I want to remove row if it is not required - it depends on the selection of
estate_type control:

for (var r = 0; r < propertyRows.length; r++)
{
if (visibility[document.announcement.estate_type.selectedIndex][r] == 0)
{
var theRow = document.getElementById('property_fields').rows[r + 1];
document.getElementById('property_fields').removeC hild(theRow); // HERE
PROBLEM: nothing happends
}
}

(there's 2-dimensional table called visibility).

The problem is that removeChilds() does nothing, there is no visual effect.
I use FireFox in Linux.
Please help. Thanks in advance.
/RAM/
Jul 1 '08 #1
10 3176
On Jul 1, 3:38 pm, r_ahims...@poczta.onet.pl wrote:
On index.html page I have a table with id="property_fields".

<table id="property_fields" name="property_fields" border="0">
<snip>
var theRow = document.getElementById('property_fields').rows[r + 1];
document.getElementById('property_fields').removeC hild(theRow);
// HERE PROBLEM: nothing happends
In HTML documents/DOMs TR elements are not children of TABLE elements
(though in XHTML documents/DOMs they may be) but rather the children
of (possibly implied) TBODY, THEAD or TFOOT elements, so your - theRow
- is not a child of the element on which you are calling - removeChild
- and as a result the method call is non-effective. A relatively
simple fix would be to call the - removeChild - method of the element
that was the - parentNode - of - theRow -. I.E:-

theRow.parentNode.removeChild(theRow);
Jul 1 '08 #2
r_********@poczta.onet.pl wrote:
On index.html page I have a table with id="property_fields".

<table id="property_fields" name="property_fields" border="0">
`table' elements don't have a `name' attribute.
It contains set of rows with the following IDs:

var propertyRows = new Array(
"region_row", "town_row", "district_row", "address_row", "house_row", "floor_no_row", "rooms_row", "floors_row", "area_row", "year_built_row",
"ownership_row", "standard_row", "garrage_row", "parking_row", "kitchen_row", "balcony_row", "gas_row", "media_row", "equipment_row", "guard_row",
"building_type_row", "picture1_row", "picture2_row", "picture3_row", "property_remarks_row"
);

I want to remove row if it is not required - it depends on the selection of
estate_type control:

for (var r = 0; r < propertyRows.length; r++)
{
if (visibility[document.announcement.estate_type.selectedIndex][r] == 0)
{
var theRow = document.getElementById('property_fields').rows[r + 1];
document.getElementById('property_fields').removeC hild(theRow); // HERE
PROBLEM: nothing happends
}
}

(there's 2-dimensional table called visibility).

The problem is that removeChilds() does nothing, there is no visual effect.
Depends on how you define that. There is an exception in the Error Console.
I use FireFox in Linux.
The `tr' element is the child of a `tbody' element, not of the `table'
element, and repeated reference lookup is inefficient.

var sel = document.forms["announcement"].elements["estate_type"];
var selIdx = sel.selectedIndex;
if (selIdx -1)
{
var table = document.getElementById('property_fields');
if (table)
{
var tbody = (table.tBodies || [null])[0];
if (tbody)
{
for (var r = propertyRows.length; r--;)
{
if (visibility[selIdx][r] == 0)
{
var theRow = tbody.rows[r + 1];
tbody.removeChild(theRow);
}
}
}
}
}

I presume `r + 1' is because you want the table header to stay in. If you
put that row into a `thead' element and the rest explicitly in the `tbody'
element (that is always there), you can use `r' instead.

You should use two or four spaces for indentation instead.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Jul 1 '08 #3
Henry wrote on 01 jul 2008 in comp.lang.javascript:
>
theRow.parentNode.removeChild(theRow);
Why is this spec-ed in this strange double way?

A child can only be a child of it's parent,
in this asexual DOM world?

Could we forget about .removeChild()
if we have the below function removeElement()?

function removeElement(x) {
x.parentNode.removeChild(x);
};

=============================

and consequently:

function removeElementById(x) {
x = document.getElementById(x);
x.parentNode.removeChild(x);
};

Not tested!!!
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 1 '08 #4
You should use two or four spaces for indentation instead.
I would disagree, It's a chore to use code which has been written
using spaces as indentations when your trying to line up braces and
debug code. Useing tabs allows you to move things around quiker.
Using spaces does look nicer, but for jigging code around I much
prefere to use tabs.
Jul 1 '08 #5
On Jul 1, 3:20 pm, yukabuk <yuka...@googlemail.comwrote:
>You should use two or four spaces for indentation instead.

I would disagree, It's a chore to use code which has been
written using spaces as indentations when your trying to
line up braces and debug code. Useing tabs allows you
to move things around quiker. Using spaces does look nicer,
but for jigging code around I much prefere to use tabs.
Thomas' statement is possibly insufficiently qualified. Code posted to
this group should not be formatted/indented with tabs because
newsreader software has been observed to default the number of spaces
per tab used for presentation to values at least in the range zero to
8, and may or may not offer the user the opportunity to set an
alternative). Having a tab converted to zero spaces renders it
useless, and in general 8 spaces pre tab would be too many, and tend
to quickly force line length over the suggested 72(ish) character norm
and result in code that is broken by automatic line wrapping.

Code should be presented to the group with formal indentation, pre-
line wrapped to avoid any automatic line wrapping, and executable
following a cut and paste from the newsreader. Indenting such posted
code with (small numbers of) spaces considerably helps in those
regards.

Jul 1 '08 #6
yukabuk wrote:
>You should use two or four spaces for indentation instead.

I would disagree, It's a chore to use code which has been written
using spaces as indentations when your trying to line up braces and
debug code. Useing tabs allows you to move things around quiker.
Not with a decent editor. Using tabs especially provides inconsistent
display among editors and pagers.
Using spaces does look nicer, but for jigging code around I much
prefere to use tabs.
This recommendation was merely about posting code here, however with a
decent editor there is no need for tab characters in editing as well, while
still minimizing the keystrokes for formatting code.

For example, I use Eclipse's WTP/WST/JSDT editor, with which I can increase
indentation by one level, two spaces, by pressing the Tab key, and decrease
it by the same amount of spaces by pressing Shift+Tab. This also works for
multi-line selections. <http://www.eclipse.org/webtools/>

When quoting, please include, and don't remove, the attribution line.

<http://www.jibbering.com/faq/faq_notes/clj_posts.html>
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Jul 1 '08 #7
On Jul 1, 4:16*pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
(...)
Could we forget about .removeChild()
if we have the below function removeElement()?

function removeElement(x) {
* * * * x.parentNode.removeChild(x);

};
(...)
Yes, but don't forget to return the removed element :

function removeElement(x) {
return x.parentNode.removeChild(x);
};

So that the calls can be nested :

document.body.appendChild(removeElement(e));

--Jorge.
Jul 1 '08 #8
Jorge wrote on 01 jul 2008 in comp.lang.javascript:
On Jul 1, 4:16*pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
>(...)
Could we forget about .removeChild()
if we have the below function removeElement()?

function removeElement(x) {
* * * * x.parentNode.removeChild(x);

};
(...)

Yes, but don't forget to return the removed element :

function removeElement(x) {
return x.parentNode.removeChild(x);
};

So that the calls can be nested :

document.body.appendChild(removeElement(e));
function removeElement(el) {
return el.parentNode.removeChild(el);
};

function transplantElement(el,targ) {
targ.appendChild(removeElement(el));
};

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 1 '08 #9
On Jul 1, 10:33*pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
Jorge wrote on 01 jul 2008 in comp.lang.javascript:
On Jul 1, 4:16*pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
(...)
Could we forget about .removeChild()
if we have the below function removeElement()?
function removeElement(x) {
* * * * x.parentNode.removeChild(x);
};
(...)
Yes, but don't forget to return the removed element :
function removeElement(x) {
* * * * return x.parentNode.removeChild(x);
};
So that the calls can be nested :
document.body.appendChild(removeElement(e));

function removeElement(el) {
* *return el.parentNode.removeChild(el);

};

function transplantElement(el,targ) {
* *targ.appendChild(removeElement(el));

};
function transplantElement(el,targ) {
** return ** targ.appendChild(removeElement(el));
};

transplantElement(e, body).className= "bodyStyle";

--Jorge.
Jul 1 '08 #10
Jorge wrote on 01 jul 2008 in comp.lang.javascript:
On Jul 1, 10:33*pm, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
>Jorge wrote on 01 jul 2008 in comp.lang.javascript:
On Jul 1, 4:16*pm, "Evertjan." <exjxw.hannivo...@interxnl.net>
wrote:
(...)
Could we forget about .removeChild()
if we have the below function removeElement()?
>function removeElement(x) {
* * * * x.parentNode.removeChild(x);
>};
(...)
Yes, but don't forget to return the removed element :
function removeElement(x) {
* * * * return x.parentNode.removeChild(x);
};
So that the calls can be nested :
document.body.appendChild(removeElement(e));

function removeElement(el) {
* *return el.parentNode.removeChild(el);

};

function transplantElement(el,targ) {
* *targ.appendChild(removeElement(el));

};

function transplantElement(el,targ) {
** return ** targ.appendChild(removeElement(el));
};

transplantElement(e, body).className= "bodyStyle";
;-)

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 1 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Sarah Haff | last post by:
Hi, What would be minimilistic XSLT that does "nothing" (no transformation) to the given XML content. Thank you. Sarah Haff
1
by: Joe Philip | last post by:
I created a file called data.del using export like this: export to data.del of del select * from sy9.c001 Now, I want to import this data to a different database into a different table. This...
1
by: dhnriverside | last post by:
Hi I'm trying to create some JS to enable/disable some form elements when a radio button grp is set to a certain option. However, the Attributes.Add method does nothing... html.. ...
1
by: siddharth | last post by:
when i am finding a particular row in a database through a datatable.row.find(the particular text to find) it gives me table does not have primary key although it has a primary key
15
by: Naha | last post by:
Hi guys, Having a problem, my table does not get displayed, when i load the page it gives me the following error(p.s-the codes below): <%@ page import="java.util.*,java.io.*" %> <%@ page...
0
by: Marc Gravell | last post by:
I have a handful of ClickOnce installs that work fine almost everywhere... however, on some machines it simply does nothing! These are regular VS2005 ClickOnce "publish" deployments, signed with a...
1
by: muhremehr | last post by:
hi all can someone one help me why this code does nothing to my database ?!! Sub Main() Dim da As New AdventureWorks_DataDataSetTableAdapters.EmployeeTableAdapter() Dim employees As...
12
by: Philipp.Weissenbacher | last post by:
Hi all! This is most certainly a total newbie question, but why doesn't the following code cause a segfault? void insertion_sort(int a, int length) { int i; for (i=0; i < length; i++) { int...
1
Knut Ole
by: Knut Ole | last post by:
hi, the acCmdDeleteRecord seems to be working, but in fact does nothing in the following code. (line 10.) If virginr = True Then strMsg = "Do you really want to CANCEL the new...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
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,...
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
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...
0
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,...

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.