469,319 Members | 2,218 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,319 developers. It's quick & easy.

Problem with replaceChild()

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 2268
acoder
16,027 Expert Mod 8TB
In replaceChild, the new child is the first argument, not the second - see link.
Nov 27 '07 #2
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
FIXED IT!

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

Post your reply

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

Similar topics

2 posts views Thread by Joe Kelsey | last post: by
3 posts views Thread by Michał Kurowski | last post: by
6 posts views Thread by joe | last post: by
2 posts views Thread by bissatch | last post: by
4 posts views Thread by meehirjha1 | last post: by
9 posts views Thread by Hallvard B Furuseth | last post: by
1 post views Thread by biswaranjan.rath | last post: by
1 post views Thread by Viral | last post: by
8 posts views Thread by mike_solomon | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.