• Resolved rui9075918

    (@rui9075918)


    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;

    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 = {};

    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

    (@codepeople)

    Hello @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:

    
    <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

    (@rui9075918)

    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.