Passing a value into a form field from the web page the form is embedded into

  • Profile Image
    tmbrighton
    Asked on June 15, 2020 at 03:43 PM

    Hi,

    I have a web page, when a user has signed I can use javascript to get the user name. The page has a Jotform embedded into it. I want to pass the user name into a field on the form so when it's submitted that user name is part of the submission. I have a hidden field on the form I want to use to store that value. Is this possible?

    Cheers!

  • Profile Image
    Niko_N
    Answered on June 15, 2020 at 08:11 PM

    Greetings,

    Yes, that will be possible. Let's take my demo form below:

    https://form.jotform.com/201667489502057


     This is corresponding iframe code:

    <iframe

          id="JotFormIFrame-201667489502057"

          title="Form"

          onload="window.parent.scrollTo(0,0)"

          allowtransparency="true"

          allowfullscreen="true"

          allow="geolocation; microphone; camera"

          src="https://form.jotform.com/201667489502057"

          frameborder="0"

          style="min-width: 100%; height: 539px; border: none;"

          scrolling="no">

    </iframe>


    You need to change the URL in the src field with the URL that has pre-populated values.

    You can use https://prepopulate.jotform.io/ to prepopulate fields. In my case, if I want to prepopulate First name and Las name fields with Niko Jotform I need to use this URL:

    https://form.jotform.com/201667489502057?name[first]=Niko&name[last]=Jotform

    However, if you have some variables that store name information, you can define the following:

    You can prepopulate URL using the JS template literals ${} to pass values of your variables and then use this link as a src for embed:

    You can copy the used code from here:

    https://pastebin.com/mtvngL30

    I've tested and it works without any issues:

    Please give a try and let me know if you have any further questions.

    Thank you in advance!