Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If a select tag has visibility:hidden, is its value submitted on form submit?

Tags:

html

If you applied visibility: hidden to a select tag, are its values submitted when you submit the form it's in?

Example CSS:

.my-select {
  visibility: hidden;
}

Example HTML:

<select class="my-select">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>
like image 608
readonly Avatar asked Feb 27 '15 02:02

readonly


People also ask

What does visibility hidden do in CSS?

The visibility CSS property shows or hides an element without changing the layout of a document. The property can also hide rows or columns in a <table> .

How do you ensure a select form field is submitted when it is disabled?

Instead of disabling the select , disable all of the option s and use CSS to gray out the select so it looks like its disabled. Add a click event handler to the submit button so that it enables all of the disabled dropdown menus before submitting the form.

How do you make a select field hidden?

You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid. A hidden <option> element is not visible, but it maintains its position on the page. Removing the hidden attribute makes it re-appear.


2 Answers

Yes.

visibility: hidden; will hide the element, but use the space it would have otherwise taken. It is still enabled and thus its data still sent.

and

display: none; will hide the element, completely (space and all). It is still enabled and thus its data still sent.

You (currently) cannot disable via CSS, but can via Javascript or JQuery. CSS is for styling, not function.

How do I disable form fields using CSS?

You can style disabled fields: http://www.w3schools.com/cssref/sel_disabled.asp

like image 126
SigSeg Avatar answered Oct 21 '22 15:10

SigSeg


Yes, it is submitted.     

like image 23
mrks Avatar answered Oct 21 '22 17:10

mrks