开发者

htmlbox post value with form submit

i'm using the htmlbox jquery plugin, if i submit the form when just having entered some text but not using any of the toolbar buttons, the old data is being submitted instead of the new edited text. When i hit a toolbarbutton first (to make some text bold for example) the new text IS being submitted.

I see the plugin has get_html and get_text functions: am i supposed to first query the wysiwygeditor before submitting or is there something else i'm missing?

The example given on the plugin-website uses a custom submitmethod, I prefer not having a controllermethod开发者_如何学运维 serverside (asp mvc) just for posting one textfield, i prefer posting the complete form using a regular <input type=submit ..>

edit: this works as workaround but just feels wrong

$('#form').submit(function() { (hb.val(hb.get_html())); });


To use HtmlBox's built-in functions, do this: Assign the return of htmlbox() to a variable and then call HtmlBox's methods using that variable (e.g. hb_full.get_html(); or any other method). See code example below.

<script type="text/javascript">
    var hb_full;
$(document).ready(function(){
        hb_full = $("#htmlbox_full").css("height", "300").css("width", "100%").htmlbox({
            toolbars: [
                [
                    // Cut, Copy, Paste
                    "separator", "cut", "copy", "paste",
                    // Undo, Redo
                    "separator", "undo", "redo",
                    // Bold, Italic, Underline, Strikethrough, Sup, Sub
                    "separator", "bold", "italic", "underline", "strike", "sup", "sub",
                    // Left, Right, Center, Justify
                    "separator", "justify", "left", "center", "right",
                    // Ordered List, Unordered List, Indent, Outdent
                    "separator", "ol", "ul", "indent", "outdent",
                    // Hyperlink, Remove Hyperlink, Image
                    "separator", "link", "unlink", "image"
                ],
                [
                    // Show code
                    "separator", "code",
                            // Formats, Font size, Font family, Font color, Font, Background
                    "separator", "formats", "fontsize", "fontfamily",
                    "separator", "fontcolor", "highlight",
                ],
                [
                    //Strip tags
                    "separator", "removeformat", "striptags", "hr", "paragraph",
                    // Styles, Source code syntax buttons
                    "separator", "quote", "styles", "syntax"
                ]
            ],
            about: true, // "false" to hide About button
            idir: "./img/HtmlBoxImg/",
            icons: "default", //all options: "default", "silk"
            skin: "blue"      //all options: "silver", "blue", "green", "red"
        });
    });

    function getHtmlFromEditor()
    {
        var HtmlFromEditor = hb_full.get_html();
        alert(HtmlFromEditor);
    }
    </script>

    <textarea id="htmlbox_full"></textarea>
<button onclick="getHtmlFromEditor();">Display HTML</button>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜