php - 如何将 html5 输出标签中的数据检索到 php 变量中?
问题描述
我的 html 代码中有一个输出标签,它是来自两个输入的数学计算
<form oninput="duyd.value = (+tot.value)-(+paid.value);"action="createinvoice.php" method="post" name="my-form">
<output name="tot" for="subtot lasdue" id="tot" ></output>
<input type="submit" name="Submit" value="Submit">
</form>
now i was to use this output data into a php variable . For example
$tot = $_POST['tot'];
但它不起作用。任何解决方案?
得到解决方案-_-
而不是输出标签,只需使用使用相同 id 和 name 的输入标签。还要检查 for 部分
<input type="text" id="duyd" name="dued" for="tot paid">
解决方案
这是使用 JavaScript 填充隐藏<input>
以及的一种解决方案<output>
:
var form = document.getElementById('my-form');
form.addEventListener('input', function() {
this.tot.value = this.tot_display.value = this.subtot.value - this.lasdue.value;
});
<form action="//httpbin.org/post" method="post" id="my-form">
<input type="text" name="subtot">
<input type="text" name="lasdue">
<input type="hidden" name="tot">
<output name="tot_display"></output>
<input type="submit" name="submitted" value="Submit">
</form>
以下是发布内容的示例:
{
"submitted": "Submit",
"subtot": "5",
"lasdue": "1",
"tot": "4"
}
推荐阅读
- postgresql - GCP CloudSQL (PostgreSQL) 在存储过程执行和故障转移期间崩溃
- angular - Angular - Sample Down 无法加载响应数据
- reactjs - 使用 agora 视频聊天可以实现端到端加密 (e2ee) 吗?
- javascript - 通过 React Router 中的 props 将数据从一个类传递到另一个类
- apache-karaf - 在 org.apache.karaf.command.acl.maven.cfg 文件中加密密码
- ruby-on-rails - 嵌套时Ruby(rails)冲突的类和模块名称
- c# - 如何确保使用 Interlocked.CompareExchange() 仅启动一项任务
- c# - Visual Studio 构建在 Roslyn csc.exe 上挂起
- javascript - 开玩笑/异步/等待不使用节流方法
- r - 找不到函数“ggplot”