Title: Set fieldname from javascript advanced equation
Last modified: February 14, 2021

---

# Set fieldname from javascript advanced equation

 *  Resolved [igonro](https://wordpress.org/support/users/igonro/)
 * (@igonro)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/set-fieldname-from-javascript-advanced-equation/)
 * I’m trying to set to certain value a field of type “calculated field” from the
   Javascript advanced equation editor.
 * I know that if you return the value, it will appear in the form, but I have one
   function that computes several values (some values are dependent of other values)
   and in order to optimize my calculator I want to just use this function call 
   to compute all the necessary fields.
 * I noticed that CFF always replaces “fieldnameX” with the value of that field.
 * Currently I use this:
    `document.getElementById("fieldname" + "13_1").value =
   years;`
 * and it works, but, is there a more elegant way of using “fieldnameX” without 
   replacing it?
 * Thanks!

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

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/set-fieldname-from-javascript-advanced-equation/#post-14046637)
 * Hello [@igonro](https://wordpress.org/support/users/igonro/)
 * Yes, of course. you can use the following piece of code as part of the equation:
 *     ```
       getField(13).setVal(years);
       ```
   
 * Best regards.
 *  Thread Starter [igonro](https://wordpress.org/support/users/igonro/)
 * (@igonro)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/set-fieldname-from-javascript-advanced-equation/#post-14046647)
 * Thank you very much for your quick reply! This is what I was looking for.
 * Best regards.

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

The topic ‘Set fieldname from javascript advanced equation’ 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/)

 * 2 replies
 * 2 participants
 * Last reply from: [igonro](https://wordpress.org/support/users/igonro/)
 * Last activity: [5 years, 3 months ago](https://wordpress.org/support/topic/set-fieldname-from-javascript-advanced-equation/#post-14046647)
 * Status: resolved