隐藏的输入需要文本

时间:2013-03-23 21:22:21

标签: javascript jquery html

我有人帮助我并获得此代码。

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

这个JavaScript

<script>
document.getElementById("charge_total").value = document.getElementById("system_cost").innerHTML;

我的问题是我使用的主机支付系统需要隐藏输入才能有名称。

所以隐藏的输入必须是这样的。

<input type="hidden" id="charge_total" name="charge_total" value="charge_total">

我的问题是使用代码是因为它没有在字段中输入任何文本而且我在结帐页面中留下了空白。我需要这个跨度ID来输出它在这行代码中的隐藏值输入中的任何数字。

<p>Total: <span id="system_cost">&nbsp;</span></p>

<input type="hidden" id="charge_total" name="charge_total" value="charge_total">

任何人都知道我做错了什么?


以下是我将其放入标题的方式。

<script>
$(function(){ //on document ready attach handlers
$('form').on('submit', function(e){
    e.preventDefault(); // stop the form submitting and do work
    $('#charge_total').val(parseFloat($('#system_cost').text()));
    $(this).submit(); //now submit the form, calculations are done
});
});
</script>

这些是另外两行。

<input type="hidden" name="charge_total" value="charge_total">

<p>Total: <span id="system_cost">&nbsp;</span></p>

跨度显示在页面上,就像假设和填充正确一样。它只是显示charge_total的隐藏值。

1 个答案:

答案 0 :(得分:1)

$(function(){ //on document ready attach handlers
    $('form').on('submit', function(e){
        e.preventDefault(); // stop the form submitting and do work
        $('#charge_total').val(parseFloat($('#system_cost').text()));
        this.submit; //now submit the form, calculations are done
    });
});
相关问题