views:

18

answers:

1

Hi,

I'm trying to manipulate the edit-body field with javascript just before I save a node in Drupal and can't seem to modify the content with consistent results. I used the following example code:

var oEditor = FCKeditorAPI.GetInstance('edit-body');
htmlstr = "<p>Hello World</p>";
oEditor.SetData(htmlstr);

And sometimes my changes are going through and other times my content is duplicated.

I tried disabling the wysiwyg editor so I can see the raw html code and tried alter the edit-body field with Javascript and that didn't do anything. The edit-body field remained the same.

Can anybody shed any light on this?

Thanks Steve

A: 

You should consider doing this in a validation or submit handler instead. That way you wont be dependent on the user's browser.

You can do this by using hook_form_alter.

googletorp
That's actually a good point, should've spotted that earlier. Cheers!
Steven Cheng