• Resolved tylerriversadmin

    (@tylerriversadmin)


    Hello,

    I’m trying to figure out a way to change the default radio button selection in HTML or javascript using the plugin.

    I know that you can set the default selection in the form settings. The use case here is that I’ve used the plugin to build a pricing calculator that will give a price quote for multiple products. I don’t want to duplicate the calculator entirely (one for every product) just to change the default selection; is there a way to apply a condition to the shortcode, or automatically select a different radio button with javascript after the form loads?

    I hope that’s clear. Thanks in advance for any guidance you can provide.

    https://ww.wp.xz.cn/plugins/calculated-fields-form/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author codepeople

    (@codepeople)

    Hi,

    Yes of course. Please, assign a class name to the radio buttons field, for example: myfield

    Note: The class is assigned to the field through the attribute: “Add Css Layout Keywords”

    Now, If you want select the choice dynamically at run time, add a new attribute to the shortcode of the form, for example, if the “id” of the form is the number 1, and there is an option in the radio buttons field whose value is for example: “xyz”, you can insert the shortcode in the page as follows:

    [CP_CALCULATED_FIELDS id=”1″ myvar=”xyz”]

    Finally, insert a “HTML Content” field in the form with the piece of code:

    <script>
    fbuilderjQuery(document).one( 'showHideDepEvent', function(){
      fbuilderjQuery('.myfield input[value="'+myvar+'"]').prop('checked', true);
    } );
    </script>

    and that’s all.

    Best regards.

    Thread Starter tylerriversadmin

    (@tylerriversadmin)

    Thanks so much for your reply!

    That is definitely working, but only for individual pages – the way I have the forms set up is on one page using tabs. The Javascript changes the value on all of the instances of the form to whichever is the last value set in the last form shortcode. Any tips?

    Plugin Author codepeople

    (@codepeople)

    Hi,

    In this case I recommend you replace the code in the “HTML Content” field by the following one:

    <script>
    fbuilderjQuery(document).one( 'showHideDepEvent', function(){
      fbuilderjQuery('.pbNext').on('click', function(){
    	var e = fbuilderjQuery('.myfield:visible input[value="' + myvar + '"]');
    	if (e.length && typeof myflag == 'undefined') {
    		e.prop('checked', true);
    		myflag = true;
    	}
      });
    } );
    </script>

    Best regards.

    Thread Starter tylerriversadmin

    (@tylerriversadmin)

    Just had a chance to implement this, and sadly it isn’t having any effect; any suggestions?

    Plugin Author codepeople

    (@codepeople)

    Hi,

    Please, be sure you are using the corresponding class name in your form, and have defined correctly the variable in the shortcode.

    I’ve inserted the code in my own form, and it is working fine.

    If you need additional help with your project, or for checking the structure of your form, please, do not hesitate in request a custom coding service through my personal website:

    http://cff.dwbooster.com/customization

    Best regards.

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

The topic ‘Change Default Radio Button Selection’ is closed to new replies.