[英]How to retrieve data from html5 output tag into php variable?
我的 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'];
但它没有工作。 任何解决方案?
得到解决方案-_-
而不是 output tag ,只需使用使用相同 id 和 name 的 input tag 。 还检查部分
<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"
}
您可以通过以下方式阅读:
const alpha = document.querySelector('form.inverse output[name=tot]').value;
而不是 output tag ,只需使用使用相同 id 和 name 的 input tag 。 还检查部分
<input type="text" id="duyd" name="dued" for="tot paid">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.