• Resolved robotor

    (@robotor)


    Hello,
    I was wondering if It is possible to populate a user-editable, single-line text field with a variable as a default value – on page load.

    1. Set variable on page using [CP_CALCULATED_FIELDS_VAR name=”varname”]
    2. Load the form after, using [CP_CALCULATED_FIELDS id=”1″]
    3. Visitor visits the page with ?varname=1 in the URL
    4. ??? Somehow pull the value of varname into a single line text field that the user can edit

    Thank you!

    • This topic was modified 7 years, 2 months ago by robotor.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter robotor

    (@robotor)

    The solution:

    If the global variable with the value to use is: my_var, and the “Single Line Text” is the fieldname1 field, you can insert in the form a “HTML Content” field, with the following piece of code as its content:

    <script>
    fbuilderjQuery(document).one('showHideDepEvent', function(){
    fbuilderjQuery('[id*="fieldname1_"]').val(my_var).change();
    });
    </script>
    Plugin Author codepeople

    (@codepeople)

    Hello @robotor.

    There are other alternatives:

    – Inserting the value from the equation associated to a calculated field, using the following line of code as part of the equation:

    fbuilderjQuery('[id*="fieldname'+'1_"]').val(my_var).change();

    – Inserting a javascript blog directly in the web page’s content as follows:

    <SCRIPT>
    cpcff_default = { 1 : {} };
    cpcff_default[1][ 'fieldname1' ] = my_var;
    </SCRIPT>

    Best regards.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Populate a single-line text field with a variable on page load’ is closed to new replies.