[英]Get value of span id for hidden type value
I currently have a form that adds up the total value and puts the number inside a span id. 我目前有一种将总值加起来并将其放在span ID中的表格。
<p>Total: <span id="system_cost"> </span></p>
I need that value to be put back into a hidden type value. 我需要将该值放回隐藏类型值中。
<INPUT TYPE=”HIDDEN” NAME=”charge_total” VALUE=”system_cost”>
Im not very good at javascript and am having trouble figuring this out so any help would be very appreciated. 我不是很擅长javascript,并且在弄清楚这一点时遇到了麻烦,因此我们将不胜感激。 I need the id to populate inside the hidden type value.
我需要ID来填充隐藏类型值。
[edit] sorry I put the wrong code in. [/edit] [编辑]对不起,我输入了错误的代码。[/编辑]
Try this: 尝试这个:
HTML HTML
<p>Total: <span id="system_cost"> </span></p>
<input type="hidden" value="charge_total" id="hidden_cost" />
JS JS
var span = document.getElementById('system_cost');
var hidden = document.getElementById('hidden_cost');
hidden.value = span.innerHTML;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.