How can I pass a value into a form using javascript?

  • RafeConnects
    Asked on October 15, 2018 at 5:50 PM

    I could do it with PHP like this 

     

    It is src=http://form.jotform.com/form/13084453420?keyword=[insert_php]echo $_GET["keyword"];


    How do I do it with Javascript? 

  • Elton Support Team Lead
    Replied on October 15, 2018 at 9:53 PM

    From where are you fetching the values? With javascript, you will have to write a code that would construct the form URL along with query string and output it into an element or a field.

    Example: Click the RUN button to test it

    https://www.w3schools.com/code/tryit.asp?filename=FW0TPK4DFCMP

    If you need further assistance, let us know.

  • RafeConnects
    Replied on October 16, 2018 at 11:45 AM

    This is great, but can you give me the code to embed it as well?  I don't want it to pop up on a different screen.  Just set the Variable value as "Test" and set it to embed and use this form. 


    Thanks!  


    https://form.jotform.com/jsform/82644164821255

  • RafeConnects
    Replied on October 17, 2018 at 12:02 PM

    HEy could you help with this? 

  • Elton Support Team Lead
    Replied on October 17, 2018 at 12:30 PM

    I'll work on a sample code and let you know.

  • Elton Support Team Lead
    Replied on October 17, 2018 at 12:56 PM

    Here's an example:

    <script>

    var keywordValue ="test";

    document.write('<script type="text/javascript" src="https://form.jotform.com/jsform/82644164821255?keyword='+keywordValue+'"><'+'/script>');

     

    </script>

    Change the ones in bold text which is the keyword value.

     

  • RafeConnects
    Replied on October 17, 2018 at 1:06 PM

    Hey thanks so much, I just need one more thing, I'm trying to PAss the URL value into the variable with Javascript and I tried the thing above, but I don't really know javascript and it doesn't work.  

    Can you fix it?  Thanks amazing help if you can get this to work ! 

    <script>

     

    function ParseURLParameter(Parameter)

    {

    var FullURL = window.location.search.substring(1);

    var ParametersArray = FullURL.split('&');

    for (var i = 0; i < ParametersArray.length; i++)

    {

    var CurrentParameter = Parameters[i].split('=');

    if (CurrentParameter[0] == Parameter)

    {

    return CurrentParameter[1];

    }

    }

    }

    var PageName = ParseURLParamater('page');

     

     

    var keywordValue ="Rafe";

     

    document.write('<script type="text/javascript" src="https://form.jotform.com/jsform/82644164821255?whatIs='+PageName+'"><'+'/script>');

     

    </script>

  • Aytekin JotForm Founder
    Replied on October 17, 2018 at 1:33 PM

    Unfortunately, it is not possible for us to provide javascript code on this support. You may want to hire a web developer for this. I'd recommend using Upwork.