将复选框更改为在文本字段值更改时选中



我有一个慈善页面,其中包括添加额外捐款的选项。捐赠者必须选中该复选框,然后在文本字段中添加金额才能添加。但似乎有些人在文本字段中添加金额时忽略了复选框,因此不包括额外的捐赠。

这是我的HTML代码——

<input alt="Additional Donation" id="other_donation_check" onclick="UpdateCost()" 
type="checkbox" value="on" />
I would like to make an (additional) <em><strong>tax-deductible</strong></em> 
donation of $<input id="other_donation_amount" name="other_donation_amount" 
onblur="UpdateCost()" onchange="UpdateCost()" onclick="UpdateCost()" 
onfocus="UpdateCost()" size="8" type="text" />

如果向文本字段添加任何金额,我可以向选中复选框的代码添加什么?

尝试:

<script>
    function check() {
        document.getElementById('other_donation_check').checked = true;
    }
</script>
<input alt="Additional Donation" id="other_donation_check" onclick="UpdateCost()" type="checkbox" />
I would like to make an (additional) <em><strong>tax-deductible</strong></em>
donation of $<input id="other_donation_amount" name="other_donation_amount" onkeyUp="check()"  size="8" type="text" />

小提琴:http://jsfiddle.net/jzz0sapc/

最新更新