简体   繁体   English

如何将html5输出标签中的数据检索到php变量中?

[英]How to retrieve data from html5 output tag into php variable?

I have a output tag in my html code , which is a mathematical calculation from two inputs我的 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'];

But itsnt working .但它没有工作。 any solution ?任何解决方案?

Got the solution -_-得到解决方案-_-

Instead of output tag , just use input tag using same id and name .而不是 output tag ,只需使用使用相同 id 和 name 的 input tag 。 also check the for part还检查部分

 <input type="text" id="duyd" name="dued" for="tot paid">

Here's one solution using JavaScript to populate a hidden <input> as well as the <output> :这是使用 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>

Here's an example of what's posted:以下是发布内容的示例:

{
  "submitted": "Submit",
  "subtot": "5",
  "lasdue": "1",
  "tot": "4"
}

您可以通过以下方式阅读:

const alpha = document.querySelector('form.inverse output[name=tot]').value;

Instead of output tag , just use input tag using same id and name .而不是 output tag ,只需使用使用相同 id 和 name 的 input tag 。 also check the for part还检查部分

 <input type="text" id="duyd" name="dued" for="tot paid">

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

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