Imagine you have a form where you switch visibility of several fields. And if the field is not displayed you don't want its value to be in request.
How do you handle this situation?
Imagine you have a form where you switch visibility of several fields. And if the field is not displayed you don't want its value to be in request.
How do you handle this situation?
What I did was just remove the elements entirely when the form is submitted:
var myForm = document.getElementById('my-form')
myForm.addEventListener('submit', function (e) {
e.preventDefault()
var form = e.currentTarget
var hidden = form.getElementsByClassName('hidden')
while (hidden.length > 0) {
for (var i = 0; i < hidden.length; i++) {
hidden[i].remove()
}
}
form.submit()
})