Form Field ID for Custom Script

  • 5 September 2018
  • 1 reply
  • 18 views

I’d like to ask if anybody knows the script on how to get hidden field ID e.g. Hidden field ID is “hiddenField” then we’d like to assign a dynamic value to Hidden Field.

Our Sample code:

document.getElementById(‘hiddenField’).value = window.location.href.split(’?’)[1];

A response is really appreciated.


1 reply

Hey! This seems related 😉 Passing a querystring variable to a hidden field

Here’s a limited solution where “something” is your query param and “randomField” is the thing you want to pass along when the form is submitted.

<script>
  $(document).ready(function () {
    var urlParams = new URLSearchParams(window.location.search);
    document.getElementById('randomField').value = urlParams.get('something');
  });
</script>

Reply