Forum

The forum is a free service supported by community members. Please consider opening a support ticket if you need timely help.

PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 22 Mar 2021 02:33 PM by  Sam Blair
Set Value of Dynamic Form Elements in Checkout
 6 Replies
Sort:
You are not authorized to post a reply.
Page 1 of 212 > >>
Author Messages


New Member


Posts:12
New Member


--
19 Mar 2021 01:33 AM

    We have upgraded to the latest verion of Storefront and in our site we set dynamic form values with Jquery so the customer doesn't have to enter in additional information.  With the new version using knockout.js the typical $("#MyFormField").val("Bob Jones") doesn't work anymore.  Anyone have an idea of how to set these after knockout renders the DOM?

    0


    Veteran Member


    Posts:2956
    Veteran Member


    --
    19 Mar 2021 01:17 PM

    Hi Sam

    This should work with jQuery. I think you need to set a delay or put the code after the Knockout has initialized?

    If you read the JS code near the bottom of the template, you'll typically find the Knockout initializes around the place where you find the code (search for "databind()" ):

    xxx.databind()

    You can then do your work here after the databind. Make sure you are still targetting the correct element if you are selecting by ID.

    0


    New Member


    Posts:12
    New Member


    --
    19 Mar 2021 02:19 PM
    So I tried that but it didn't work.  So in that template, are you saying that i should put my code after the checkoutContainer.databind()?  When I do that it doesnt' appear to work.  An example of my code is 

    $("input[name=StudentName]").val("Bob Jones").  Is that correct?  Thanks for your help!

    0


    Veteran Member


    Posts:2956
    Veteran Member


    --
    19 Mar 2021 02:24 PM

    Yes, put it after the checkoutContainer.databind()

    You can check your jQuery code is valid first by going to your checkout page and opening up the developer tool (F12) and the paste your Javascript into the Console and hit Enter. See if your script actually changes the textbox value. Normally, I think you need a quote around the 'StudentName' attribute value. Give it a try.

    $("input[name='StudentName']").val("Bob Jones")

    0


    Veteran Member


    Posts:2956
    Veteran Member


    --
    19 Mar 2021 02:24 PM

    Yes, put it after the checkoutContainer.databind()

    You can check your jQuery code is valid first by going to your checkout page and opening up the developer tool (F12) and the paste your Javascript into the Console and hit Enter. See if your script actually changes the textbox value. Normally, I think you need a quote around the 'StudentName' attribute value. Give it a try.

    $("input[name='StudentName']").val("Bob Jones")

    0
    You are not authorized to post a reply.
    Page 1 of 212 > >>