mjamar
mjamar

Reputation: 15

How to remove and not hide fields element in a form?

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"; 

Upvotes: 1

Views: 733

Answers (2)

DaveS
DaveS

Reputation: 3294

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().

Upvotes: 1

Shashank
Shashank

Reputation: 11

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.

Upvotes: 1

Related Questions