MooEditable不会发布textarea值

时间:2014-03-11 08:56:11

标签: javascript php forms

我有一张表格:

<script type="text/javascript">
    window.addEvent('domready', function(){
        $('tresc_wiecej').mooEditable({
            actions: 'bold italic underline strikethrough | formatBlock justifyleft justifyright justifycenter justifyfull | insertunorderedlist insertorderedlist indent outdent insertHorizontalRule | undo redo removeformat | createlink unlink | urlimage | toggleview'
        });
</script>
<form id="theForm" action="?a=send_news" method="post">
    <label>Title: </label>
    <input type="text" name="title"></input>

    <label>Text:</label>
    <textarea  name="text" id="tresc_wiecej" >
    ss
    </textarea>

    <label>Tags: </label>
    <input type="text" name="tag"></input>
    <input type="submit" value="Send">
</form>

PHP

if ($_GET['a'] == "send_news")
{
    $title=$_POST['title'];
    $tag=$_POST['tag'];
    $text=$_POST['text'];
}

我可以毫无问题地收到值:tag,title,但是即使我使用了一些默认值(ss),textarea也是空的。

解决方案:

要添加脚本:

    function getData()
{

 document.getElementById('hid').value = $(tresc_wiecej').mooEditable().getContent();
}

完整脚本:

<script type="text/javascript">
    window.addEvent('domready', function(){
        $('tresc_wiecej').mooEditable({
            actions: 'bold italic underline strikethrough | formatBlock justifyleft justifyright justifycenter justifyfull | insertunorderedlist insertorderedlist indent outdent insertHorizontalRule | undo redo removeformat | createlink unlink | urlimage | toggleview'
        });

        function getData()
    {

     document.getElementById('hid').value = $(tresc_wiecej').mooEditable().getContent();
    }

</script>

要形成添加隐藏输入:

<input type="hidden" name="hid" id="hid">

点击提交按钮添加动作getData():

<input type="submit" onclick="getData()" value="Send">

完整格式:

<form id="theForm" action="?a=send_news" method="post">
    <label>Title: </label>
    <input type="text" name="title"></input>

    <label>Text:</label>
    <textarea  name="text" id="tresc_wiecej" >

    </textarea>
    <input type="hidden" name="hid" id="hid">

    <label>Tags: </label>
    <input type="text" name="tag"></input>
    <input type="submit" value="Send">
</form>

和PHP

$text=$_POST['hid'];

1 个答案:

答案 0 :(得分:0)

<script type="text/javascript">
    window.addEvent('domready', function() {
        $('textarea-1').mooEditable();

       // Post submit
        $('theForm').addEvent('submit', function(e) {
        alert($('textarea-1').value);
        return true;
    });
});

<form id="theForm" method="post" action="">
    <label for="textarea-1">Textarea 1 (try paste copied text!)</label>
    <textarea id="textarea-1" name="editable1"></textarea>
    <input type="submit">
</form>