Javascript submit from an RTE
Forums »
General discussion
» Javascript submit from an RTE
sadie
Minotaur I.T.
|
2008/05/25 19:21
I have a javascript button that calls submit: <a href='javascript:document.myform.submit();'>
Other wysiwyg editors usually require you to call document.myform.onSubmit() first. What's the recommended way in Dynarch for making sure the contents of a rich text editor are submitted with a form? |
mishoo
Dynarch.com
|
2008/05/26 12:30
You must fill the contents of the <textarea> element with the HTML from the RTE widget. Something like this (where editor is the DlRteFrame widget): function doSubmit() { // fill the <textarea> var ta = document.getElementById("id-of-textarea"); ta.value = editor.getHTML(); // submit now document.getElementById("id-of-form").submit(); } and your link: <a href="javascript:doSubmit()">
DynarchLIB.com |
sadie
Minotaur I.T.
|
2008/05/27 13:43
And if the editor isn't a global variable? Imagine I have several RTEs on a page. Can I look up an RTE by id? function doSubmit() { var editor = ???; // fill the <textarea> var ta = document.getElementById("id-of-textarea"); ta.value = editor.getHTML(); // submit now document.getElementById("id-of-form").submit(); } |
mishoo
Dynarch.com
|
2008/05/27 13:58
There are multiple solutions... it's completely up to you how you manage your variables. Here's a possibility (it's probably not documented — sorry about this). All widgets have an unique ID (automatically generated). After you create the editor, you can save its ID in the textarea, and retrieve it later: var rte = new DlRteFrame({ ... }); document.getElementById("id-of-textarea").rteID = rte.id; // later... var ta = document.getElementById("id-of-textarea"); var rte = DlWidget.getById(ta.rteID); ta.value = rte.getHTML(); Note that instead of ID, you can actually save a reference to the widget itself. Hope this helps. DynarchLIB.com |
sadie
Minotaur I.T.
|