Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use jQuery to change a field when another field value has changed
    primarykey
    data
    text
    <p>I searched and even with answers like <a href="https://stackoverflow.com/questions/12287996/jquery-change-value-when-value-of-other-input-field-is-changed">JQuery: Change value when value of other input field is changed</a>, I have been unable to figure this out.</p> <p>I am trying to do some math based on HTML form input. When the user enters numbers in the first and second field, I want it to automatically calculate into the third field to show the total.</p> <p>My form code is:</p> <pre><code>&lt;div id="makingARecurringGift"&gt; Enter Recurring Gift Amount: $&lt;input type="number" min="0" name="recurringDonationValue" id="recurringDonationValue" size="15" value="0" /&gt;&lt;br /&gt; I would like to make this gift for &lt;input type="number" min="0" max="60" name="numberOfMonths" id="numberOfMonths" size="15" value="0" /&gt; months.&lt;br /&gt; Total Gift Amount of $&lt;input type="number" min="0" value="0" name="totalRecurringDonationValue" /&gt;. &lt;/div&gt; </code></pre> <p>My javascript that I am trying to run is:</p> <pre><code>function replaceRecurringDonationValue() { //make our variables so we don't forget var perDonationValue = 0; var numberOfMonths = 0; var TotalRecurringDonationValue = 0; //give them their correct values perDonationValue = $("#recurringDonationValue").val(); numberOfMonths = $("#numberOfMonths").val(); //ensure that the maximum number of months is enforced. if(numberOfMonths &gt; 60) { alert("Donations can last for a maximum of 60 months."); $("#numberOfMonths").val(60); } TotalRecurringDonationValue = perDonationValue * numberOfMonths; $("#TotalRecurringDonationValue").val(TotalRecurringDonationValue); } $("#recurringDonationValue").change(replaceRecurringDonationValue()); $("#numberOfMonths").change(replaceRecurringDonationValue()); </code></pre> <p>If you would like to view the full main page source code: <a href="http://pastebin.com/aLMqYuxc" rel="nofollow noreferrer">http://pastebin.com/aLMqYuxc</a> and full javascript source is: <a href="http://pastebin.com/FvviPHhj" rel="nofollow noreferrer">http://pastebin.com/FvviPHhj</a></p> <p>Sorry if this is a dumb question, thank you all for your assistance. I'm still trying to figure this out.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload