简体   繁体   English

如何将该表格分为两个值

[英]How Can I Split this form in two values

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?? 提交好后,我怎么能得到两个值?我想知道隐藏值和另一个包含div文本的值吗? the reason why it because im going to insert both of those values in different variables to insert into a mysql query 之所以这样,是因为我打算将这两个值插入不同的变量中以插入到mysql查询中

html code: html代码:

<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: JavaScript代码:

function insert_value()
{
  var values = [];
    values.push(document.getElementById('hidden_data').value);
    values.push(document.getElementById('showing_data').textContent);
    console.log(values);
  return true;
}

Replace div with textarea and to disable resizing use css: textarea替换div并使用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: 在HTML中添加以下行:

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

And your javascript code: 和您的JavaScript代码:

function insert_value()
{
    var html = document.getElementById('showing_data').textContent;
    document.getElementById('data_result').value = html;
    return true;
}

just replace the div with textarea and add style = "resize:none" to the text area 只需将div替换为textarea,然后在文本区域中添加style = "resize:none"

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

and change following line in the javascript 并更改javascript中的以下行

document.getElementById('showing_data').value;

you can make it textarea and you can have hidden value of that. 您可以将其设置为textarea,并且可以具有隐藏的价值。

    <textarea id="showing_data"  rows="4" cols="50">

and if you dont want to be draggable just use this in css 如果您不想拖拽,请在CSS中使用它

 textarea
{
 resize: none;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM