Use javascript to change the form displayed?

  • Profile Image
    MetalSupport
    Asked on March 17, 2016 at 11:32 AM

    Hi there,

    I am currently trying to use some Javascript code to dynamically change the form displayed on a page. I first tried it by changing the src attribute on the <script> tag but this wouldn't work as the script would not run again.

    I then tried embedding the form as an Iframe and changing the src attribute with Javascript. This actually worked! However, the form's conditions would not work anymore. The form has a condition where it pulls and URL parameter (city) and runs a few conditions based on that (echo GET['city'];).

    It just seems that the echo GET['url-parameter']; tag does not work when the form is embed as an iFrame. The final result that I am trying to achieve is that if the url parameter city=houston, the form for Houston appears and if city=newyork, the form for NYC appears.

    Would you please provide suggestions on how to address one of the following issues:

    - GET['url'] tag not working in iFrames

    - A simpler way to switch the form that is being embed on the site via Javascript

    Thanks!

  • Profile Image
    david
    Answered on March 17, 2016 at 11:53 AM

    The easiest way to accomplish this would be to have two forms embedded to a main form using iFrame widgets:

    http://www.jotform.com/help/148-Getting-the-Form-iFrame-Code

    The main form would have a selection for "City" and would conditionally show the appropriate city form when the option is selected:

    http://www.jotform.com/help/57-Smart-Forms-Using-Conditional-Logic

  • Profile Image
    david
    Answered on March 17, 2016 at 11:54 AM

    My apologies, I link the iFrame code, rather than the iFrame widget.  Here is the proper link for the widget:

    http://widgets.jotform.com/widget/iframe_embed