473,472 Members | 2,184 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

.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 3736
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
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
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,...
1
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...
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...
1
isladogs
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.