Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Friday, June 17, 2016

HTML select: how to set default text which won't be shown in drop-down list?

HTML select: how to set default text which won't be shown in drop-down list?


I mean such situation: I have select which shows by default Select language, but when I open all choices there don't have to be the Select language option (but it must stay in the header of select to time when user selects some option), because it's not an option - it is only header.

Answer by Kyle for HTML select: how to set default text which won't be shown in drop-down list?


Because you can't use assign placeholders for select tags, I don't believe that there is any way to do exactly what you're asking for with pure HTML/CSS. You can, however, do something like this:

  

"Select language" will show up in the dropdown, but once another option is selected it will not be possible to reselect it.

I hope that helps.

Answer by Baldrick for HTML select: how to set default text which won't be shown in drop-down list?


I have a solution with a span displayed above the select until a selection done. The span displays the default message, and so it's not in the list of propositions:

HTML:

Default message    

CSS:

#default_message_overlay {      position: absolute;      display: block;      width: 120px;      color: grey;  }  select {      width: 150px;  }  

Javascript (with JQuery):

$(document).ready(function() {      // No selection at start      $('#my_select').prop("selectedIndex", -1);        // Set the position of the overlay      var offset = $('#my_select').offset();      offset.top += 3;      offset.left += 3;      $('#default_message_overlay').offset(offset);        // Remove the overlay when selection changes      $('#my_select').change(function() {          if ($(this).prop("selectedIndex") != -1) {              $('#default_message_overlay').hide();          }      });  });  

I've made a jsfiddle for demo. Tested with Firefox and IE8.

Answer by Nobita for HTML select: how to set default text which won't be shown in drop-down list?


Kyle's solution worked perfectly fine for me. Adding a value of "selected" to the item we want to appear as a header forces it to show in the first place as a placeholder. Something like:

  

The complete markup should be along these lines:

  

You can take a look at this fiddle.

Answer by Aakash for HTML select: how to set default text which won't be shown in drop-down list?


Try this:

In the CSS:

.selectSelection option:first-child{  display:none;  

}

Answer by Prabhu for HTML select: how to set default text which won't be shown in drop-down list?


Here is the solution:

  

class="titleans">Answer by Oriol for HTML select: how to set default text which won't be shown in drop-down list?

The proper and semantic way is using a placeholder label option:

  • Add an option element as the first child of the select
  • Set value= "" to that option
  • Set the placeholder text as the content of that option
  • Add the required attribute to the select

This will force the user to select another option in order to be able to submit the form, and browsers should render the option as desired:

If a select element contains a placeholder label option, the user agent is expected to render that option in a manner that conveys that it is a label, rather than a valid option of the control.

However, most browsers will render it as a normal option. So we will have to do fix it manually, by adding the following to the option:

select > .placeholder {    display: none;  }

Answer by Anders M. for HTML select: how to set default text which won't be shown in drop-down list?


  

you can of course move the css to a css file if you want, and put a script to catch the esc button to select the disabled again. Unlike the other similar answers I put value="", this is so if you send the value(s) of your select list with a form, it won't contain "chose something". In asp.net mvc 5 sent as json compiled with var obj = { prop:$('#ddl').val(),...}; and JSON.stringify(obj); the value of prop will be null.

Answer by Ashok for HTML select: how to set default text which won't be shown in drop-down list?


.selectmenu{      	-webkit-appearance: none;  /*Removes default chrome and safari style*/  	-moz-appearance: none; /* Removes Default Firefox style*/  	background: #0088cc ;  	width: 200px; /*Width of select dropdown to give space for arrow image*/  	text-indent: 0.01px; /* Removes default arrow from firefox*/  	text-overflow: "";  /*Removes default arrow from firefox*/ /*My custom style for fonts*/  	color: #FFF;  	border-radius: 2px;  	padding: 5px;      border:0 !important;  	box-shadow: inset 0 0 5px rgba(000,000,000, 0.5);  }  .hideoption { display:none; visibility:hidden; height:0; font-size:0; }
Try this html    

here have good link for how to set css for select menu it's help you for make good design for select menu

http://www.htmllion.com/default-select-dropdown-style-just-css.html


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

Related Posts:

0 comments:

Post a Comment

Popular Posts

Fun Page

Powered by Blogger.