How to preselect an option from a dropdown menu with JavaScript

Posted on: April 21st, 2023
By: Tadeo Lemus

window.addEventListener('DOMContentLoaded', function() {
  // find the "Department" dropdown element
  var departmentDropdown = document.querySelector('select[name="input_11"]');
  departmentDropdown.value = 'value of option with spaces';

The eventListener for DOMContentLoaded is optional, it’s preferable to simply load the JavaScript in the footer.

If you are familiar with Gravity Forms, you will see this is a Gravity Forms class, but as long as you select the dropdown with its class or ID, it should work the same for any dropdown.

Have any questions or comments? Write them below!

Leave a Reply

Your email address will not be published. Required fields are marked *