Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1444079

    Hello,
    I am lookin for a way to set a specific option in the Form Select Element as “selected”. Can someone help with a tip on how to do that?

    #1444547

    Hey lyubopopov,
    Thank you for the link to your site, try adding this code to the end of your child theme functions.php file in Appearance ▸ Editor, or if you are not using a child theme you could use the WP Code plugin then add a new snippet, in the top right corner use the PHP snippet as the code type:
    Enfold_Support_2680.jpeg
    then add this code and save:

    function select_value_in_form() { ?>
      <script>
    document.addEventListener('DOMContentLoaded', function() {
        var selectFields = document.querySelectorAll('.page-id-15 #avia_6_1');
        selectFields.forEach(function(selectField) {
            for (var i = 0; i < selectField.options.length; i++) {
                if (selectField.options[i].value === 'Brazil') {
                    selectField.selectedIndex = i;
                    break;
                }
            }
        });
    });
    </script>
      <?php
    }
    add_action( 'wp_footer', 'select_value_in_form', 99 );
    

    Please ensure to copy the code from the forum and not an email notification so the symbols are not converted.
    I wrote this to only work on the one page so it won’t interfere with other pages.

    Best regards,
    Mike

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.