Title: switch function on load
Last modified: October 16, 2023

---

# switch function on load

 *  Resolved [rui9075918](https://wordpress.org/support/users/rui9075918/)
 * (@rui9075918)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/switch-function-on-load/)
 * Good afternoon. I would like to know if you can help me with a question? I have
   a switch function, whose initial value, when the page is loaded, is assigned 
   by another switch function. It happens that when loading the page, the first 
   function mentioned does not run completely.
 * The value contained in fieldname1 is correct, as it gives the desired values.
   fieldname2 is a radioButtons field. Both functions below are in a Calculated 
   Field. Is it possible for them to help?
 *  Here’s the example:
 * var url = fieldname1;
 *     ```wp-block-code
       switch(url) {
           case 1:
               getField(2).setVal('1');
   
               break;
           case 2:
               getField(2).setVal('2');
   
               break;
           case 3:
               getField(2).setVal('3');
   
               break;
   
           default:
               return ('1');
   
               break;
       }
       ```
   
 * })();
 * (function masterSwitch(){
   var css = {};
 *     ```wp-block-code
       switch(fieldname2) {
           case 1:
               css['border'] = ' solid transparent';
               css['borderImage'] = 'url(image1.png) 30';           
               break;
           case 2:
               css['border'] = ' solid transparent';
               css['borderImage'] = 'url(image2.png) 30';
               break;
           case 3:
               css['border'] = ' solid transparent';
               css['borderImage'] = 'url(image3.png) 30';
               break;
   
           default:
               css['border'] = ' solid transparent';
               css['borderImage'] = 'url(image1.png) 30';
               break;
       }
   
       jQuery('#image').each(function(){jQuery(this).css(css);});
       ```
   
 * })();

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

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/switch-function-on-load/#post-17127227)
 * Hello [@rui9075918](https://wordpress.org/support/users/rui9075918/)
 * If you want to run the script after rending the form, you can insert an “HTML
   Content” field in the form and enter the following piece of code as its content:
 *     ```wp-block-code
       <script>
       fbuilderjQuery(document).on('formReady', function(){
           let v = getField('fieldname1').val(true, true);
           getField('fieldname2').setVal(IF(IN(v, [1,2,3]), v, 1));
       });
       </script>
       ```
   
 * Best regards.
 *  Thread Starter [rui9075918](https://wordpress.org/support/users/rui9075918/)
 * (@rui9075918)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/switch-function-on-load/#post-17127251)
 * Thank you for the quick response. I will try.

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

The topic ‘switch function on load’ 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: [rui9075918](https://wordpress.org/support/users/rui9075918/)
 * Last activity: [2 years, 7 months ago](https://wordpress.org/support/topic/switch-function-on-load/#post-17127251)
 * Status: resolved