Simple JavaScript code to set a cookie and write the value somewhere
Link the script cookie.js.
Call the function writeCookieOnPlace(name_of_the_cookie_or_parameter, name_of_the_input_place_id) to:
- Check for the given paramenter or cookie. If the parameter exists, the cookie is saved (overwritten if exists).
- The value of the cookie is saved to the input with the selected id
writeCookieOnPlace('affiliate', 'affiliateName')
- The code above will look for the parameter "affiliate" on the URL, like: http://yourweb.com/?affiliate=12345
- If if exists, will save the value to a cookie with the name "affiliate". If a cookie already exists with that name, it will be overwritten.
- If the parameter or the cookie exists, the value will be written on the value of the input field with the id 'AffiliateName'