doudun1029
2013-10-10 09:00
浏览 37
已采纳

如何将此表单拆分为两个值

How can i end up with two values after submit okay i was wondering how can i have the hidden value and another value containing the div text?? the reason why it because im going to insert both of those values in different variables to insert into a mysql query

html code:

<form action="" method="POST" onsubmit="return insert_value()">
    <input id="hidden_data" name="data" type="hidden" value="<?php $user_id ?>"/>
        <div id="showing_data" class="commenttext" contenteditable="true"></div>
    <input type="submit" value="Submit" id="submitthis" />
</form>

Javascript CODE:

function insert_value()
{
  var values = [];
    values.push(document.getElementById('hidden_data').value);
    values.push(document.getElementById('showing_data').textContent);
    console.log(values);
  return true;
}
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

  • dongyuan2388 2013-10-10 09:07
    最佳回答

    Replace div with textarea and to disable resizing use css:

    textarea {
        resize: none;
    }
    

    To answer your real question, but slightly modifying it; instead of merging them both in one input create another hidden input.

    in HTML add this line:

    <input type="hidden" name="data_result" id="data_result" />
    

    And your javascript code:

    function insert_value()
    {
        var html = document.getElementById('showing_data').textContent;
        document.getElementById('data_result').value = html;
        return true;
    }
    
    评论
    解决 无用
    打赏 举报
查看更多回答(2条)

相关推荐 更多相似问题