Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can't address new content

    Hi all.

    I have an ajax function that goes to the server and retrieves a form, which it then places inside a <div>'s innerHTML, "edit" in this case. The form renders on the screen, but then my script tries to set a few field values and fails.

    Here's what I've got:

    ajax.get("/templates/editor.html", 1, true, "edit");

    This function works and the content of editor.html is displayed on the screen:

    <div id="edit_frame">
    <div id="edit_toolbar">
    <span>X</span>
    </div>
    <div id="edit_panel">
    <form name="main">
    <textarea rows=25 cols=50 name="edit_content" id="edit_content">
    This is where the content will be edited...
    </textarea>
    </form>
    </div>
    </div>

    <script>
    up();
    </script>

    The up() function is defined in the original page and also gets called.

    function up () {
    alert(ajax.req.responseText);
    alert(document.getElementById("edit_content"));

    document.getElementById("edit_content").value = document.getElementById(edit.source).innerHTML;
    }

    The first alert() displays the form's source, as expected. The second alert() displays "null," then the rest of the script seems to continue one.

    So, how do I get "edit_content" to become part of the DOM so I can manipulate it?

    TIA,
    Mike.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    You either need to add it tot he page before you can start working with it or you need to creat an element and set the innerHTML of that.

    Code:
    var div = document.createElement("div");
    div.innerHTML = ajax.req.responseText;
    alert(div.getElementsByTagName("span").length);
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

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