Change checkbox to checked when text field value changes

822 views Asked by At

I have a charity page which includes an option to add an additional donation. The donor must check the checkbox then add the amount in a text field for it to be added. But it appears some are overlooking the checkbox when adding the amount in the text field, and so the additional donation is not being included.

Here is the HTML code I have--

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

What can I add to the code that checks the checkbox if any amount is added to the text field?

1

There are 1 answers

1
M. Page On

Try:

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

Fiddle: http://jsfiddle.net/jzz0sapc/