• Resolved nealbo

    (@nealbo)


    So I have the setup where I have a calculated field:

    redirectToURL('https://www.somesite.com/search/'+myvar+'+'+fieldname4)

    Which is triggered by a “calculate” button. i.e. dynamically evaluate is turned off in the form settings. “myvar” is a variable that is created in the shortcode (if that matters).

    This works and it sucessfully redirects to the URL, and evaluates myvar and fieldname4 on button click.

    However, I also need it so that the text on the button itself contains the “myvar” value, but of course this can’t happen because I’m not dynamically evaluating.

    Is there a way to still make the button redirect to the URL as above, but also for the button to contain the “myvar” value as soon as the page loads?

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

    (@codepeople)

    Hello @nealbo

    Assuming your button is the fieldname1, you can insert an “HTML Content” field in the form with the following code as its content:

    <script>fbuilderjQuery(document).one('showHideDepEvent', function(){
    if(typeof myvar != 'undefined') getField('fieldname1').setVal(myvar);
    });
    </script>

    Best regards.

    Thread Starter nealbo

    (@nealbo)

    @codepeople wow thank you so much for the incredibly fast response on this!

    This worked perfectly and my form is now working exactly as I wanted it to.

    Thanks again!

    Thread Starter nealbo

    (@nealbo)

    @codepeople I’ve ran into a problem that I was hoping you could help with.

    I have 2 different forms, with two different variables (set up as above), but the second form doesn’t have the button text updated using your HTML code. Is there anyway to make this work for multiple different forms with different variables ont he same page?

    Thread Starter nealbo

    (@nealbo)

    <script>fbuilderjQuery(document).one('showHideDepEvent', function(){
    if(typeof myvar != 'undefined') getField('fieldname1_1').setVal(myvar);
    if(typeof myvar2 != 'undefined') getField('fieldname5_2').setVal(myvar);
    });
    </script>

    I figured it out, when referencing with multiple forms, the second form needs _2, third needs _3 etc. for the fieldnames even when there’s no overlap. I added the _1 just for uniformity.

    Thanks again for your help, all working well now!

    • This reply was modified 2 years ago by nealbo.
    Plugin Author codepeople

    (@codepeople)

    Hello @nealbo

    There is a more elegant method.

    You can assign class names to the forms via their shortcode codes:

    [CP_CALCULATED_FIELDS id="1" class="first-form" myvar="Text A"]

    Or visually:

    And then, you can enter the following piece of code in the content of the HTML Content field

    <script>fbuilderjQuery(document).one('showHideDepEvent', function(){
    if(typeof myvar != 'undefined') getField('fieldname1', '.first-form').setVal(myvar);
    });
    </script>

    If you assign the second-form class name to the second form, you can insert an HTML Content field on it with the code:

    <script>fbuilderjQuery(document).one('showHideDepEvent', function(){
    if(typeof myvar2 != 'undefined') getField('fieldname5', '.second-form').setVal(myvar2);
    });
    </script>

    Best regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Dynamically evaluate a single variable’ is closed to new replies.