Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

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-07-2009, 09:44 PM   PM User | #1
cmancone
New Coder

 
Join Date: Mar 2009
Posts: 52
Thanks: 4
Thanked 6 Times in 6 Posts
cmancone is an unknown quantity at this point
scriptaculous: adding inplaceeditors after ajax.updater

I'm using ajax.updater to update a div, and the updated div contains a number of divs which I want to enable an inplaceeditor on. I don't know the "good" way to do this, but I found a way that largely works with one irritating hitch. I have a function that just adds inplaceeditors to all divs that have ids prefixed with 'task':

Code:
function add_editors()
{
	var divs = document.getElementsByTagName("div");
	for(var i=0; i < divs.length; i++)
	{
		var id = divs[i].id.toString();
		var pre = id.substr( 0, 4 );
		if ( pre == 'task' )
		{
			new Ajax.InPlaceEditor(id, 'process_ajax.php?upd_task=true&id=' +id);
		}
	}
}
Very hack and slash, I know. But it works. I call this function on page load and I get lots of inplaceeditors. Then, I have a function which updates the div that contains all these inplaceeditors, and the updated content is exactly the same as before, but with a couple extra divs:

Code:
function add_task()
{
	new Ajax.Updater( 'proj_id', 'process_ajax.php?new_task=proj_id', { method: 'get' });
	add_editors();
}
This code, unfortunately, doesn't work. The ajax.updater works, but none of the divs are inplaceeditors. To add to the confusion though if I make a small change:

Code:
function add_task()
{
	new Ajax.Updater( 'proj_id', 'process_ajax.php?new_task=proj_id', { method: 'get' });
	window.alert('test');
	add_editors();
}
Everything works! I get an alert, and everything turns into inplaceeditors. If I remove the window.alert(), nothing works. Similarly, if I add a window.alert as the first action in the add_editors() function, everything works! Why in the world window.alert() fixes things, I have no clue.

Any suggestions would be greatly appreciated. Also, if you can point out the proper way to do this I'm all ears. I tried adding the 'evalscripts: true' option to the ajax.updater, and passed the lines to add inplaceeditors inside the returrned content, but that didn't work at all Thanks in advanced!
cmancone is offline   Reply With Quote
Old 03-10-2009, 02:01 AM   PM User | #2
cmancone
New Coder

 
Join Date: Mar 2009
Posts: 52
Thanks: 4
Thanked 6 Times in 6 Posts
cmancone is an unknown quantity at this point
nevermind, I think I have this figured out...
cmancone 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 10:51 PM.


Advertisement
Log in to turn off these ads.