[英]can I store an innerHTML of a div into a hidden text box in javascript and php
I have to store the inner html of a table into a hidden input box. 我必须将表的内部html存储到隐藏的输入框中。 I am able to store it in a JavaScript variable but not been able to store it in the hidden input box. 我能够将其存储在JavaScript变量中,但无法将其存储在隐藏的输入框中。
Here is the code I have written so far: 这是我到目前为止编写的代码:
in .JS file 在.JS文件中
d = document.getElementById('address').innerHTML;
document.getElementById('hid1').value = d;
in .php file 在.php文件中
<input type="hidden" id="hid1" name="hid1"/>
Please help me with this...am really clueless on what to do 请帮我解决这个问题。。。我真的不知所措
If I am not mistaken, the way you have it set up currently, you will need to append the value
attribute to the <input>
before assigning a value to that element's value
property. 如果我没有记错的话,请按照当前的设置方式,将value
属性附加到<input>
然后再为该元素的value
属性分配一个值。
If you include the value
attribute in your HTML
from the start, like this: 如果从一开始就在HTML
包含value
属性,则如下所示:
<input type="hidden" id="hid1" name="hid1" value="" />
your javascript
should work exactly as you intend. 您的javascript
应该可以完全按照您的预期工作。
here is an implementation, the textfield isn't hidden (for obvious reasons).. but hiding it shouldn't be a problem. 这是一个实现,不会隐藏文本字段(出于明显的原因)..但是隐藏它应该不是问题。
var data = document.getElementById('someDiv').innerHTML;
document.getElementById('hiddenField').value = data;
this should do (ensure the id hiddenField
is unique in the document or hid1
in your case) 这应该做(确保id hiddenField
在文档中是唯一的,或者在您的情况下为hid1
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.