...

View Full Version : Can't address new content



Uberbot
03-30-2009, 09:11 PM
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.

A1ien51
04-20-2009, 02:54 PM
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.


var div = document.createElement("div");
div.innerHTML = ajax.req.responseText;
alert(div.getElementsByTagName("span").length);


Eric



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum