- Item in a List
I want to create a highly functional ContactForm7 section on my WordPress website. To enhance its functionality, I am looking to dynamically change the value of certain drop-down menus using JavaScript.
Despite searching for a solution over the past few days, I haven't found one that suits my needs yet. However, I have tried various approaches including;
It is simple to target the selector using JS:
var contactForm = document.querySelector('.wpcf7-form')
var selectedMenu = contactForm.querySelector('select[name="DropDown_Menu-1"]')
I can even display the default values of the drop-down menu that I initially set up in the CF7 edit block:
var firstValue = selectedMenu[0].value
var thirdValue = selectedMenu[2].value
However, I am facing challenges in assigning new values to individual items in the drop-down menu. Despite successfully updating their values within the code snippet, the changes are not reflected on the live website!
selectedMenu[0].value = "new Value"
var updatedValue = selectedMenu[0].value //the value is now >new Value<, but on the website, the 2nd element of the menu retains the old value
Any suggestions on how to programmatically modify these values?