Title: Set value depending on dropdown selection
Last modified: December 21, 2023

---

# Set value depending on dropdown selection

 *  Resolved [michaelrieder](https://wordpress.org/support/users/michaelrieder/)
 * (@michaelrieder)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/set-value-depending-on-dropdown-selection/)
 * Hi CodePeople
 * I do not want to stress you to much, but I didn’t find a solution in the doc.
 * How can I set the value of a slider field (e.g. getField(25).setVal(200);) depending
   on a dropdown selection.
 * Best Regards Michael
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fset-value-depending-on-dropdown-selection%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/set-value-depending-on-dropdown-selection/#post-17294303)
 * Hello [@michaelrieder](https://wordpress.org/support/users/michaelrieder/)
 * I’ll try to describe the process with a hypothetical example.
 * Assuming you have the number field fieldname1 and the slider field fieldname2,
   and you want to set the slider value by coding as follows:
 * If the fieldname1 value is less than or equal to 25, set the slider value to 
   25.
   If the fieldname1 value is greater than 25 and less than or equal to 50, 
   set the slider value to 50. Otherwise, set the value 100.
 * In this hypothetical case, you can insert a calculated field in the form to be
   used as an auxiliary and enter the equation:
 *     ```wp-block-code
       (function(){
       let value;
       if(fieldname1<=25) value = 25;
       else if(fieldname1<=50) value = 50;
       else value = 100;
   
       getField(fieldname2|n).setVal(value);
       })()
       ```
   
 * Best regards.
 *  Thread Starter [michaelrieder](https://wordpress.org/support/users/michaelrieder/)
 * (@michaelrieder)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/set-value-depending-on-dropdown-selection/#post-17294907)
 * Hi CodePeople
 * Ok, the example works. I would like to set the condition to the default choice
   of the dropdown field. like: if(fieldname1==default). If this is not possible
   then I have to use if(fieldname1|v==’xxx’). Here I have a html problem because
   within xxx I have two special characters like ‘ (apos).
 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/set-value-depending-on-dropdown-selection/#post-17295131)
 * Hello [@michaelrieder](https://wordpress.org/support/users/michaelrieder/),
 * If the default value of the Dropdown field is the text ‘default’, you must enclose
   it between single-quotes or double-quotes symbols. Like:
 *     ```wp-block-code
       (function(){
       let value;
       if(fieldname1 == 'default') value = 25;
       else value = 100;
   
       getField(fieldname2|n).setVal(value);
       })()
       ```
   
 * Best regards.

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

The topic ‘Set value depending on dropdown selection’ 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

 * [dropdown](https://wordpress.org/support/topic-tag/dropdown/)

 * 3 replies
 * 2 participants
 * Last reply from: [codepeople](https://wordpress.org/support/users/codepeople/)
 * Last activity: [2 years, 5 months ago](https://wordpress.org/support/topic/set-value-depending-on-dropdown-selection/#post-17295131)
 * Status: resolved