Auto-populate country field based on user locale | Community
Skip to main content

Auto-populate country field based on user locale

  • February 27, 2024
  • 2 replies
  • 0 views

Web23

In all of our Forms, we have a field for "Country." Is there a way to auto-populate this field depending on the user locale?

2 replies

Shawna11
  • Community Manager
  • February 27, 2024
Hey Ruth, I moved this over to our Q&A topic for better visibility with our Community to answer your question. Thank you!

  • February 28, 2024

Hello @web23

You can fill in this field with the user locale value using custom code. To programmatically populate the value from HelpCenter.user.locale into the input field you've provided, you would typically use JavaScript. Below is an example of how you might write a script to do this:

  // Assuming HelpCenter.user.locale is accessible and contains the locale value
  var userLocale = HelpCenter.user.locale;

  // Function to set the value of the input field
  function setLocaleValue() {
    // Get the input field by its ID
    var inputField = document.getElementById('request_custom_fields_14320661483540');

    // Set the value of the input field to the user's locale
    if (inputField) {
      inputField.value = userLocale;
    }
  }

  // Call the function to set the value when the page loads
  window.onload = setLocaleValue;