I want to remove a field from a form and not hide it because I want the form to retract when I hide the fields my form stays "wide" which is an aesthetic problem.
document.getElementById('test_field').style.visibility = "hidden";
it works but the form remains large (it only does the hidden)
I tried that but it doesn't work
document.getElementById("test_field").style.display = "none";
edit: document.getElementById("test_field").remove() work thank you to "DaveS".
CodePudding user response:
Instead of this you could directly add a hidden attribute in the field that you want to hide like <input type='text' hidden='true'>
this would actually make the field like its not even there but we could view it in source.
CodePudding user response:
If display = "none" didn't work for you, it sounds like you want it removed from the server's point of view. In other words, you don't want it to be submitted with the other fields. If that's the case, you can just use document.getElementById("test_field").remove()
.