更改复选框以在文本字段值更改时进行检查

时间:2014-11-28 18:18:06

标签: jquery text checkbox checked donations

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

这是我的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" />

如果在文本字段中添加了任何金额,我可以添加哪些代码来检查复选框?

1 个答案:

答案 0 :(得分:0)

尝试:

<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/

相关问题