简体   繁体   English

如何将 UTC 时间戳注入来自 Javascript 的隐藏 HTML 表单字段

[英]How to inject UTC timestamp into a hidden HTML form field from Javascript

I know next to nothing about Javascript.我对 Javascript 几乎一无所知。 I think I am almost there but need some help...我想我快到了,但需要一些帮助......

I need to pass UTC into a hidden field in an HTML form.我需要将 UTC 传递到 HTML 表单中的隐藏字段中。 The actual time doesn't really matter, just using it as an order identifier that will be unique for each order.实际时间并不重要,只需将其用作每个订单唯一的订单标识符即可。

Here is what I have but it isn't working... Appreciate any help.这是我所拥有的,但它不起作用......感谢任何帮助。

--- in form section --- --- 在表格部分 ---

<input id="pg_consumerorderid" value="" type="hidden">

--- Script just below the < /form> tag --- </form> 标签下方的脚本

<script>
var field = document.querySelector('#pg_consumerorderid');
var date = Date.now();
// Set the date
field.value = date;
</script>

All my other form fields use input name= instead of the input id= Not sure if that is messing things up.我所有的其他表单字段都使用 input name= 而不是 input id= 不确定这是否搞砸了。

Thanks!谢谢!

Kalhan.Toress said in a comment which gave the answer: Kalhan.Toress评论中说,给出了答案:

you have to keep both name and id你必须保留姓名和身份证

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

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