Answers.Body: <p>I have experienced this behavior in two different situations. In one situation, the Contribution was using a manually created price set that mimicked the behavior of the contribution page with "Allow other amounts" checked. The javascript code is not added for these price sets since CiviCRM can't really tell how they are supposed to work. Switching the contribution page to use the amount options provided by the page itself instead of a price set should solve that problem.</p>
  
  <p>However, in another case, the onclick event was not added because the price set value field's name was "Contribution_Amount" instead of "other_amount". I don't know why the price set value field's name was not created properly.</p>
  
  <p>The code in question is in CRM/Price/BAO/PriceField.php:</p>
  
  <pre><code>if (!empty($qf-&gt;_quickConfig) &amp;&amp; !empty($qf-&gt;_contributionAmount) &amp;&amp; strtolower($fieldOptions[$optionKey]['name']) == 'other_amount') {
    $label .= '  ' . $currencySymbol;
    $qf-&gt;assign('priceset', $elementName);
    $extra = ['onclick' =&gt; 'useAmountOther();'];
  }
  </code></pre>
  
  <p>I figured out which price field value record was the one being used and manually updated it with:</p>
  
  <pre><code>UPDATE civicrm_price_field_value SET name = 'other_amount' WHERE id = 934;
  </code></pre>
  
  <p>This isn't a great answer to your question - more of a work-around. Figuring out why the price field value record was added with the name set to "Contribution_Amount" would be better.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-28T20:15:01.860Z
Answers.Text: Same situation, also not sure of how that happened! (Maybe setting up a price set and then reverting?) But this fixed it. Thanks!
Answers.UserDisplayName: Laryn
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-19T16:51:21.980Z
Answers.LastActivityDate: 2019-11-19T16:51:21.980Z
Answers.UserDisplayName: Jamie
Body: <p>For CiviContribute forms in WordPress that have predefined fixed amounts ($25, $50, $100, ...) and that also allow an "Other" amount, it seems that the javascript that is supposed to clear the fixed amount radio buttons when an "other" amount is filled in is broken. I'm using Civi v.5.4.0 in WordPress v.4.9.9.</p>
  
  <p>The malfunctioning behavior is also reported <a href="https://civicrm.stackexchange.com/q/21262/5790">here</a>, but the CMS is not indicated. A couple javascript solutions are posted&mdash; but this should work out of the box with Civi, right?</p>
  
  <p>Looking under the covers, I see there are javascript functions <code>clearAmountOther()</code> and <code>useAmountOther()</code> that are wired to the <code>onclick</code> events for the radio buttons. However, the DOM structure the code refers to is invalid. There is no <code>document.Main.amount_other</code>.</p>
  
  
  
  <pre><code>function clearAmountOther() {
    var priceset = 0
    if( priceset ){
      cj(priceset).val('');
      cj(priceset).blur();
    }
    if (document.Main.amount_other == null) return; // other_amt field not present; do nothing
    document.Main.amount_other.value = "";
  }
  </code></pre>
  
  <p>As a result, if you select a fixed amount like $25 and then enter $40 into the "Other Amount" box, the contribution is the sum $65. This is likely to surprise donors!</p>
  
  <p>Is this a known issue? A bug that needs to be fixed?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-01-20T16:28:45.870Z
Comments.Text: I think a patch on this would definitely be welcome, assuming this problem exists on the latest version of Civi.  I would expect it does, frankly.  I recommend opening an issue on https://lab.civicrm.org.
Comments.UserDisplayName: Jon G - Megaphone Tech
Tags: <wordpress><civicontribute><contribution-page>
Title: On CiviContribute forms within WP, the behavior of predefined amounts and an "Other Amount" input box is broken
ThreadText: # On CiviContribute forms within WP, the behavior of predefined amounts and an "Other Amount" input box is broken
  
  (Asked by: username_0 on 2019-01-20)
  
  For CiviContribute forms in WordPress that have predefined fixed amounts ($25, $50, $100, ...) and that also allow an "Other" amount, it seems that the javascript that is supposed to clear the fixed amount radio buttons when an "other" amount is filled in is broken. I'm using Civi v.5.4.0 in WordPress v.4.9.9.
  
  The malfunctioning behavior is also reported [here](https://civicrm.stackexchange.com/q/21262/5790), but the CMS is not indicated. A couple javascript solutions are posted— but this should work out of the box with Civi, right?
  
  Looking under the covers, I see there are javascript functions `clearAmountOther()` and `useAmountOther()` that are wired to the `onclick` events for the radio buttons. However, the DOM structure the code refers to is invalid. There is no `document.Main.amount_other`.
  
  ```
  function clearAmountOther() {
    var priceset = 0
    if( priceset ){
      cj(priceset).val('');
      cj(priceset).blur();
    }
    if (document.Main.amount_other == null) return; // other_amt field not present; do nothing
    document.Main.amount_other.value = "";
  }
  
  ```
  
  As a result, if you select a fixed amount like $25 and then enter $40 into the "Other Amount" box, the contribution is the sum $65. This is likely to surprise donors!
  
  Is this a known issue? A bug that needs to be fixed?
  
  **Tags:** wordpress, civicontribute, contribution-page
  
  > **Comments:**
  > **username_1**: I think a patch on this would definitely be welcome, assuming this problem exists on the latest version of Civi.  I would expect it does, frankly.  I recommend opening an issue on https://lab.civicrm.org.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-11-19. Score: 2
  
  I have experienced this behavior in two different situations. In one situation, the Contribution was using a manually created price set that mimicked the behavior of the contribution page with "Allow other amounts" checked. The javascript code is not added for these price sets since CiviCRM can't really tell how they are supposed to work. Switching the contribution page to use the amount options provided by the page itself instead of a price set should solve that problem.
  
  However, in another case, the onclick event was not added because the price set value field's name was "Contribution\_Amount" instead of "other\_amount". I don't know why the price set value field's name was not created properly.
  
  The code in question is in CRM/Price/BAO/PriceField.php:
  
  ```
  if (!empty($qf->_quickConfig) && !empty($qf->_contributionAmount) && strtolower($fieldOptions[$optionKey]['name']) == 'other_amount') {
    $label .= '  ' . $currencySymbol;
    $qf->assign('priceset', $elementName);
    $extra = ['onclick' => 'useAmountOther();'];
  }
  
  ```
  
  I figured out which price field value record was the one being used and manually updated it with:
  
  ```
  UPDATE civicrm_price_field_value SET name = 'other_amount' WHERE id = 934;
  
  ```
  
  This isn't a great answer to your question - more of a work-around. Figuring out why the price field value record was added with the name set to "Contribution\_Amount" would be better.
  
  > **Comments:**
  > **username_3**: Same situation, also not sure of how that happened! (Maybe setting up a price set and then reverting?) But this fixed it. Thanks!  
  
  ---
  
  