Jump to content

TinyEasy

Member
  • Posts

    5
  • Joined

  • Last visited

Reputation Activity

  1. Thanks
    TinyEasy reacted to jpeter in Assign random hidden value in form field for A/B testing   
    @TinyEasy
    You can add the following javascript code below using Code Injection. When a user lands on the page,  the code will run and add a random value of either 1 or 2 to the hidden field whose name is SQF_3FREEPLANS.
    Javascript
    (function(){ // Configuration var MAX = 2; var FIELD_NAME = 'SQF_3FREEPLANS'; // Execute code if(document.readyState == 'loading') { document.addEventListener('DOMContentLoaded', randomizeFieldValue); } else { randomizeFieldValue(); } function randomizeFieldValue(){ var randomNumber = Math.floor(Math.random() * MAX) + 1; var hiddenField = document.querySelector('[name='+ FIELD_NAME +']'); hiddenField && (hiddenField.value = randomNumber); } })() Make sure to place the javascript code between <script> tag e.g.:
    <script> // Add JS Code Here </script>  
  2. Thanks
    TinyEasy reacted to jpeter in Assign random hidden value in form field for A/B testing   
    @TinyEasy Yep! As long as the value of the MAX variable is greater than 1, it'll set random numbers between 1 and the MAX value.  
×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.