473,387 Members | 1,502 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,387 software developers and data experts.

.removeChild Not Working...

Hello.

I'm trying to remove an additional radio selection if another radio button is
selected. There's suppose to be two additional selections if one particular
button is chosen. Then if the user picks another button then this additional
selection disappears.

I've been trying the removeChild method but it doesn't seem to be working.
The code is part of a larger form code, so I'll just post the problem area...

...
var radio_sel = document.getElementById("radiochoice");
radio_sel.onclick=function(){addRadioOpts();}
....

....
function addRadioOpts(){
var newcell1 = document.createElement('td');
var newInput1 = document.createElement('input');
newInput1.type = "radio";
newInput1.name = "movie";
newInput1.className = 'textstyle';
newInput1.value = 'swordfish';
var nameText1 = document.createTextNode("Swordfish");
var newInput2 = document.createElement('input');
newInput2.type = "radio";
newInput2.name = "movie";
newInput2.className = 'textstyle';
newInput2.value = 'perfect_stranger';
var nameText2 = document.createTextNode("Perfect Stranger");

newcell1.appendChild(newInput1);
newcell1.appendChild(nameText1);
newcell1.appendChild(newInput2);
newcell1.appendChild(nameText2);
var nextRow = document.getElementById("main_row");

var the_table = document.getElementsByTagName("tbody")[0];

var new_row = document.createElement('tr');
new_row.appendChild(newcell1);

var my_label = document.createElement('label');
my_label.className = 'textstyle';
my_label.id = "newlabel";

my_label.appendChild(new_row)
the_table.insertBefore(my_label, nextRow);

var radio_buttons = document.getElementsByName("beauty");
radio_buttons.onchange=function(){the_table.remove Child(my_label);}
return;
}
....

Any suggestion is appreciated...

--
Message posted via WebmasterKB.com
http://www.webmasterkb.com/Uwe/Forum...cript/200809/1

Sep 24 '08 #1
7 3733
ChuckB via WebmasterKB.com wrote:
var nextRow = document.getElementById("main_row");

var the_table = document.getElementsByTagName("tbody")[0];

var new_row = document.createElement('tr');
new_row.appendChild(newcell1);

var my_label = document.createElement('label');
my_label.className = 'textstyle';
my_label.id = "newlabel";

my_label.appendChild(new_row)
Why do you try to put a row ('tr' element) into a 'label' element?
the_table.insertBefore(my_label, nextRow);
And why do you try to insert a label element into a tbody? A tbody is
supposed to contain 'tr' elements.
var radio_buttons = document.getElementsByName("beauty");
radio_buttons.onchange=function(){the_table.remove Child(my_label);}
getElementsByName returns a collection, I don't know of any collection
having an onchange handler.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 24 '08 #2
Martin Honnen wrote:
>var nextRow = document.getElementById("main_row");
[quoted text clipped - 8 lines]
>>
my_label.appendChild(new_row)

Why do you try to put a row ('tr' element) into a 'label' element?
>the_table.insertBefore(my_label, nextRow);
I did that because without it the text for the additional buttons didn't have
the same style as the surrounding text for the form. The surrounding text for
the form had a class of ' .textstyle'. So each form element had surrounding
<labeltags. Like <label for="dish" class="textstyle">....</label>
I was having difficulty assigning this class to the <inputtag so I just
assigned it to the <labeltag and appended the <trw/ the <inputto it.
>
And why do you try to insert a label element into a tbody? A tbody is
supposed to contain 'tr' elements.
As mentioned, all of my 'tr' elements are surround by <labeltags.
>var radio_buttons = document.getElementsByName("beauty");
radio_buttons.onchange=function(){the_table.remov eChild(my_label);}

getElementsByName returns a collection, I don't know of any collection
having an onchange handler.
I was told that this way would be better than

var whatever = document.getElementsByTagName("input")...then

loop through and then...

if (whatever[i].name=="beauty")
{
whatever[i].onchange=function() {};
}

....

any other suggestions?

--
Message posted via WebmasterKB.com
http://www.webmasterkb.com/Uwe/Forum...cript/200809/1

Sep 24 '08 #3
SAM
Le 9/24/08 3:43 PM, ChuckB via WebmasterKB.com a écrit :
Martin Honnen wrote:
>>var nextRow = document.getElementById("main_row");
[quoted text clipped - 8 lines]
>>my_label.appendChild(new_row)
Why do you try to put a row ('tr' element) into a 'label' element?
>>the_table.insertBefore(my_label, nextRow);

I did that because
You cannot put a TR in a LABEL
that is not correct HTML (absolutely forbidden !)
I was having difficulty assigning this class to the <inputtag so I just
assigned it to the <labeltag and appended the <trw/ the <inputto it.
why not assigning it to the TR ou the DT contining the radio buttons
or ... just style the label apended in the TD

Don't see the difficulty
I think you are complicationning your resulting html

>And why do you try to insert a label element into a tbody? A tbody is
supposed to contain 'tr' elements.

As mentioned, all of my 'tr' elements are surround by <labeltags.
Not possible ! forbidden
nothing can be inserted between </trand <tr>
nor than between </tdn' <td <tableand <tbodyand so on for all
proper tags of a table

>>var radio_buttons = document.getElementsByName("beauty");
radio_buttons.onchange=function(){the_table.remo veChild(my_label);}
getElementsByName returns a collection, I don't know of any collection
having an onchange handler.

I was told that this way would be better than
Where ?
var whatever = document.getElementsByTagName("input")...then

loop through and then...

if (whatever[i].name=="beauty")
{
whatever[i].onchange=function() {};
}

...

any other suggestions?
Try to construct your page in pure and correct HTML
(with its form with the table and labels or/and inputs in TDs)
then create your CSS
then delete (or change in comments) the TRs or TDs or LABELs you do no
more want.

Once all that is made, now and only now, you can tempt to create your JS
to toggle those objets you want to appear/disappear
(don't forget to verify With Firefox's extention "Firebug" if all is OK
on each JS's modification of the page)

--
sm

Sep 24 '08 #4
On Sep 24, 2:18*pm, "ChuckB via WebmasterKB.com" <u46201@uwewrote:
I'm trying to remove an additional radio selection if another radio button is
selected. There's suppose to be two additional selections if one particular
button is chosen. Then if the user picks another button then this additional
selection disappears.
That's an inconsistent description. The first sentence suggests that
you want to make the additional section become as if it had never been
coded. The third sentence suggests what you want it to become
invisible, without saying whether the space which it used to appear in
should be collapsed or retained with background. And you have not
said what is to happen if the particular button is subsequently
unchosen.

Clarify your thinking; you, or one of us, may then be able to provide
an appropriate solution.

Server-side code, if any, should be able to ignore data fields which
other data indicates are unwanted.

--
(c) John Stockton, near London, UK. Posting with Google.
Mail: J.R.""""""""@physics.org or (better) via Home Page at
Web: <URL:http://www.merlyn.demon.co.uk/>
FAQish topics, acronyms, links, etc.; Date, Delphi, JavaScript, ....|


Sep 24 '08 #5
SAM
Le 9/24/08 3:18 PM, ChuckB via WebmasterKB.com a écrit :
Hello.

I'm trying to remove an additional radio selection if another radio button is
selected. There's suppose to be two additional selections if one particular
button is chosen. Then if the user picks another button then this additional
selection disappears.
see this other post :
<http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/e5a11e7b8dccc7b2/bd8f6998df792ea8#bd8f6998df792ea8>
whith same homework
Sep 24 '08 #6
SAM wrote:
>Le 9/24/08 3:18 PM, ChuckB via WebmasterKB.com a écrit :
>Hello.

I'm trying to remove an additional radio selection if another radio button is
selected. There's suppose to be two additional selections if one particular
button is chosen. Then if the user picks another button then this additional
selection disappears.

see this other post :
<http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/e5a11e7b8dccc7b2/bd8f6998df792ea8#bd8f6998df792ea8>
whith same homework
Wow!...this almost the same exact question...the only difference is that the
link is dealing with checkbox options, while mine is a radio button.

I'll look at your suggestion here and comment later...Thanks..

--
Message posted via WebmasterKB.com
http://www.webmasterkb.com/Uwe/Forum...cript/200809/1

Sep 25 '08 #7
On Sep 24, 9:43 pm, "ChuckB via WebmasterKB.com" <u46201@uwewrote:
Martin Honnen wrote:
var radio_buttons = document.getElementsByName("beauty");
radio_buttons.onchange=function(){the_table.remove Child(my_label);}
getElementsByName returns a collection, I don't know of any collection
having an onchange handler.

I was told that this way would be better than

var whatever = document.getElementsByTagName("input")...then

loop through and then...
In some ways it is better because you'll probably get fewer items
searching for things named "beauty" compared to searching for all
input tags. But BOTH
getElementsByName and getElementsByTagName return collections. So you
STILL need to loop through:

var radio_buttons = document.getElementsByName("beauty");
for (var i=0;i<radio_buttons.length;i++) {
radio_buttons[i].onchange = function(){
the_table.removeChild(my_label);
}
}

Sep 25 '08 #8

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

Similar topics

1
by: JehanNYNJ | last post by:
I need to clear out the HTML contents of a <span> element and then re-add that element as a blank span. Here is the code... var elem = document.getElementById(spanId); var deletedElem =...
2
by: Stewart | last post by:
Originally posted in comp.lang.javascript: Newsgroups: comp.lang.javascript From: "Stewart" Date: 23 Aug 2005 02:50:04 -0700 Local: Tues, Aug 23 2005 10:50 am Subject: FireFox, RemoveChild,...
4
by: VA | last post by:
I have the following code (modified) from RobG on this newsgroup... function moveColumn(table_id,col_id, dir) { var table=document.getElementById(table_id); var idx=GetCellIndex(col_id,table);...
5
by: Markus Stehle | last post by:
Hi all! I want to remove a node from a nodelist by using RemoveChild. I'm using the following code: XmlNode root = Xml.DocumentElement; XmlNodeList items = root.SelectNodes("Item"); XmlNode...
1
by: Rebecca Tsukalas | last post by:
Hello, I have a problem concerning removeChild. This is the XML structure I use with php: <xml_thing <language1 <site>bla1</site <site>bla2</site <site>bla3</site </language1
5
WebDunce
by: WebDunce | last post by:
Hi guys, I am trying to develop a simple xml editor. I have an object that has a TreeView. I use the TreeView to display the Xml node info. That's all fine, but i want the user to be able to move...
10
by: r_ahimsa_m | last post by:
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...
5
by: r_ahimsa_m | last post by:
Hello, I am lerning HTML/CSS/JavaScript. I created HTML page with table "property_fields" containing 24 rows ('tr' elements). I want to remove last 23 rows: var table =...
1
by: ChuckB via WebmasterKB.com | last post by:
Hello. I'm trying to remove an additional radio selection if another radio button is selected. There's suppose to be two additional selections if one particular button is chosen. Then if the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.