Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-30-2009, 08:11 PM   PM User | #1
Uberbot
New to the CF scene

 
Join Date: Dec 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Uberbot is an unknown quantity at this point
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.
Uberbot is offline   Reply With Quote
Old 04-20-2009, 01:54 PM   PM User | #2
A1ien51
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
A1ien51 will become famous soon enough
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]
A1ien51 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:44 PM.


Advertisement
Log in to turn off these ads.