Skip to main content

HTML: Cum sa facem disable un element din drop down.

Uneori avem nevoie pe UI sa facem un element dintr-un drop-down disable. Utilizatorul sa il poata vedea, dar sa nu il poata selecta. Aceasta varianta este foarte utila cand un update la o aplicatie deja existenta, unele optiuni dispar. Pana cand toti utilizatori o sa isi faca update la configuratie( backward compatibility).
Pe fiecare optine dintr-un select avem atributul disable ce care il putem seta. Pana aici totul pare in regula:
<select name="telefon">     <option value="1">Nokia</option>     <option value="2" disabled="disabled">LG</option>     <option value="3">Samsung</option></select>
Optiunea de LG nu o sa poata fi selectata, dar utilizatorul o poate vizualiza, iar din codul de java script se poate selecta aceasta valoare.
Ar aparea ceva de genul acesta:

Singura problema este cu IE. Acesta nu suporta acest atribut. Pentru a rezolva acest neajuns putem sa folosim urmatorul cod javascript:
function AddOptionsDisabledSupport(){
var allSelectItems = document.getElementsByTagName('select');
for(var i=0; i < allSelectItems.length; i++){
allSelectItems[i].onchange= function(){
this.selectedIndex = -1;
if(this.selectedIndex < this.options.length - 1){

//Change the color to gray.
for(var j=0; j < allSelectItems[i].options.length; j++){
allSelectItems[i].options[j].style.color = '#CCC';

//Run each time when page is loaded.
window.attachEvent("onload", AddOptionsDisabledSupport)
Iar de acuma acest atribut o sa poata fi folosit si pe IE.


  1. Totusi, incepand cu IE >= 8.0, option disabled e suportat si de IE..

  2. Acuma am vazut commentul, in seara asta pun si vs jquery.
    Doar ca nu tot timpul avem jquery la indemana.


Post a Comment

Popular posts from this blog

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine:
threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration:

TeamCity.NET 4.51EF 6.0.2VS2013
It seems that there …

How to check in AngularJS if a service was register or not

There are cases when you need to check in a service or a controller was register in AngularJS.
For example a valid use case is when you have the same implementation running on multiple application. In this case, you may want to intercept the HTTP provider and add a custom step there. This step don’t needs to run on all the application, only in the one where the service exist and register.
A solution for this case would be to have a flag in the configuration that specify this. In the core you would have an IF that would check the value of this flag.
Another solution is to check if a specific service was register in AngularJS or not. If the service was register that you would execute your own logic.
To check if a service was register or not in AngularJS container you need to call the ‘has’ method of ‘inhector’. It will return TRUE if the service was register.
if ($injector.has('httpInterceptorService')) { $httpProvider.interceptors.push('httpInterceptorService&#…

Fundamental Books of a Software Engineer (version 2018)

More then six years ago I wrote a blog post about fundamental books that any software engineer (developer) should read. Now it is an excellent time to update this list with new entries.

There are 5 different categories of books, that represent the recommended path. For example, you start with Coding books, after that, you read books about Programming, Design and so on.
There are some books about C++ that I recommend not because you shall know C++, only because the concepts that you can learn from it.


Writing solid codeCode completeProgramming Pearls, more programming pearls(recommended)[NEW] Introduction to Algorithms


Refactoring (M. Fowler)Pragmatic ProgrammerClean code[NEW] Software Engineering: A Practitioner's Approach[NEW] The Mythical Man-Month[NEW] The Art of Computer Programming


Applying UML and Patterns (GRASP patterns)C++ coding standards (Sutter, Alexandrescu)The C++ programming language (Stroustrup, Part IV)Object-oriented programming (Peter Coad)P…