SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Deleting nodes

  1. #1
    SitePoint Zealot
    Join Date
    Aug 2006
    Location
    Newcastle, England
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Deleting nodes

    Hello,

    I have a form what dynamically generates new text fields when a numbe ris selected. I can create the new fiels by inserting more nodes, the problem is though, when a lower number is selected I need to delete any nodes what have been created.

    The new nodes wont delte and I am given this errror:

    Node was not found" code: "8

    I've simplified my code below to only show the delete stuff

    Code JavaScript:
    // Get the form field I want to delete (the codes nested in a loop, y is a number) - Tested and gets the correct element
    var formFieldElement = document.getElementById("name_"+y);
    // Get parentnode. This is a <ul> tag what is used as the parentnode
    var additionalNamesHolder = document.getElementById("additional_names_holder");
    // Remove the formfield
    additionalNamesHolder.removeChild(formFieldElement);

    I've tried deleting other nodes on the page and they delete fine, its just the dynamically created form fields that wont delete.

    Anyone had a similar problem or know where I'm going wrong.

    Thanks

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2006
    Location
    Newcastle, England
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dont worry, sorted it thanks.

    Instead of trying to remove directly, the form field i assigned an id to the li tags and removed them instead. Seems to have done the trick.

    bleeding javascript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •