Title: Complex Javascript Formula Crashes the Page
Last modified: January 10, 2017

---

# Complex Javascript Formula Crashes the Page

 *  Resolved [teddyespo](https://wordpress.org/support/users/teddyespo/)
 * (@teddyespo)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/complex-javascript-formula-crashes-the-page/)
 * I want to create a Calculated Field (CF) with the following logic:
 * If user enters 5000 or less into fieldname1, then I want this CF to display 100.
 * If user enters anything higher than 5000 into fieldname1, then I want this CF
   to calculate 100 + 0.5%.
 * Using the Equation Tutorial, I saw that I can make complex functions using Javascript.
   When I enter the following logic into the equation editor, it crashes the page
   that the form is published on:
 *     ```
       (function(){
   
       if(fieldname1 > 5000) return fieldname1*0.005+100;
   
       if(fieldname1 <= 5000) return 100;
   
       })();
       ```
   
 * Can you please help?
    -  This topic was modified 9 years, 5 months ago by [teddyespo](https://wordpress.org/support/users/teddyespo/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [teddyespo](https://wordpress.org/support/users/teddyespo/)
 * (@teddyespo)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/complex-javascript-formula-crashes-the-page/#post-8636288)
 * Not sure what the problem was, but I fixed it. The only thing I did differently
   was take the extra line space out between the lines of code:
 *     ```
       (function(){
       if(fieldname1 > 5000) return fieldname1*0.005+100;
       if(fieldname1 <= 5000) return 100;
       })();
       ```
   
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/complex-javascript-formula-crashes-the-page/#post-8638059)
 * Hello [@teddyespo](https://wordpress.org/support/users/teddyespo/),
 * There are some plugins (not ours), that replace multiple symbols of lines changes
   by `<BR>` or `<P>`, breaking the Javascript code.
 * Best regards.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Complex Javascript Formula Crashes the Page’ is closed to new replies.

 * ![](https://ps.w.org/calculated-fields-form/assets/icon-256x256.jpg?rev=1734377)
 * [Calculated Fields Form](https://wordpress.org/plugins/calculated-fields-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/calculated-fields-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/calculated-fields-form/)
 * [Active Topics](https://wordpress.org/support/plugin/calculated-fields-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/calculated-fields-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)

## Tags

 * [Equations](https://wordpress.org/support/topic-tag/equations/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [tools](https://wordpress.org/support/topic-tag/tools/)

 * 2 replies
 * 2 participants
 * Last reply from: [codepeople](https://wordpress.org/support/users/codepeople/)
 * Last activity: [9 years, 5 months ago](https://wordpress.org/support/topic/complex-javascript-formula-crashes-the-page/#post-8638059)
 * Status: resolved