473,473 Members | 4,257 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with replaceChild()

26 New Member
First, here is the code.

Expand|Select|Wrap|Line Numbers
  1. function swapMP (theMPvalue) {
  2.  
  3.     if (theMPvalue !== "custom") {
  4.         return;
  5.     }
  6.  
  7.     var customMP = document.getElementById("part_mp");
  8.     var newCustomMP = document.createElement("input");
  9.     var thePartPopup = document.getElementById("partPopup");
  10.  
  11.     newCustomMP.setAttribute("id", "part_mp");
  12.     newCustomMP.setAttribute("size", "12");
  13.     newCustomMP.setAttribute("name", "mountpoint");
  14.     newCustomMP.setAttribute("type", "text");
  15.  
  16.     thePartPopup.replaceChild(customMP, newCustomMP);
  17.  
  18. }
Expand|Select|Wrap|Line Numbers
  1. <div id="partPopup">
  2.     <label for="mountpoint">Mount Point: </label>
  3.     <select id="part_mp" name="mountpoint" onchange="javascript:swapMP(this.value);">
  4.         <option value=""></option>
  5.         <option value="/">/</option>
  6.         <option value="/boot">/boot</option>
  7.         <option value="/home">/home</option>
  8.         <option value="/usr">/usr</option>
  9.         <option value="custom">Custom ...</option>
  10.     </select>
  11. </div>
I'm trying to have it so when 'Custom ...' is selected, the select dropdown is replaced with an input box. customMP and newCustomMP both work (using alert() to verify they are set up correctly). The problem, I'm sure, is in the replaceChild() line. Does anyone know what would be the problem here? Thanks a lot!
Nov 27 '07 #1
4 2385
acoder
16,027 Recognized Expert Moderator MVP
In replaceChild, the new child is the first argument, not the second - see link.
Nov 27 '07 #2
sdustinh
26 New Member
Ooops, meant to correct that. When I try to run the script, I keep getting a DOM Exception 8 error. Which I believe is the same as the FF error of not being able to find the node.

That doesn't make sense though, if I can use alert() and see that both of them come up with an object, shouldn't it work fine? I just can't seem to find what's causing the error.

I thought maybe having the same id (which they do need to have, but not at once) could be the problem, so I changed the id of the input... and still come up with nothing.
Nov 27 '07 #3
sdustinh
26 New Member
FIXED IT!

There was another div in the way. Thanks for the help!
Nov 27 '07 #4
acoder
16,027 Recognized Expert Moderator MVP
Glad you fixed it. Another div in the way? How should that affect replaceChild()?
Nov 28 '07 #5

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

Similar topics

2
by: Joe Kelsey | last post by:
I want to create dynamic content and use replaceChild to switch out different subtrees. I start with a span placeholder: <span id="replaceMe"></span> Then I use document.getElementById...
3
by: Michał Kurowski | last post by:
What I've got: 1) a page with a "window.open('some_html', ...)" 2) "some_html" with basically this: <body onload="document.body.innerHTML=FillIt('some_id')"></body> 3) a script:
6
by: joe | last post by:
Hi Everyone, could anyone comment on the following problem: I have a textbox being appended to a cell in a table, and am trying to call focus() on like this: <snip> c01.removeChild(answerbox);...
2
by: bissatch | last post by:
Hi, I am trying to use JavaScript to write a table column on a web page. The code is as follows: <html> <head> <script> function displaycount() {
4
by: meehirjha1 | last post by:
Hello, can any body help me out.. I have some td element which have following ids ctl1_lnkPrint ctl2_lnkPrint ctl3_lnkPrint ctl4_lnkPrint ctl5_lnkPrint ... ...
9
by: Hallvard B Furuseth | last post by:
Why does the FAQ (Q 4.15) recommend innerHTML when so many here say one should use createElement(), replaceChild() etc? Also, why does the "Alternative DynWrite function" at...
1
by: biswaranjan.rath | last post by:
Hi, I'm facing problem after doing replaceChild for a DOCUMENT ELEMENT. Sample code: elem = document.getElementById( "myEle" ); var newVal; newVal = document.createElement('textbox');...
1
by: Viral | last post by:
Hello All, I have the following XML document : (for ease of understanding i am just posting a part of it) Base XML ------------ <?xml version="1.0"?> <ROOT>...
8
by: mike_solomon | last post by:
I have a button <input type="submit" name="Delete" value="Delete"> This code can not be changed I want to use Javascript to change the type I tried:
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...
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...
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,...
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: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.