I need a Select tag to have the style text-transform: uppercase and the options to be regular case.
This does not seem possible in chrome 69.
I need a Select tag to have the style text-transform: uppercase and the options to be regular case.
This does not seem possible in chrome 69.
This works for me in Chrome 69
option {
text-transform: none;
}
select {
text-transform: uppercase;
width: 5rem;
}
<select>
<option></option>
<option>one</option>
<option>Two</option>
<option>tHREe</option>
</select>
You can use javascript to capitalize the text inside the selected option
element.
// get the select element
let select = document.querySelector("select");
// create a store for each options text values
let store = [];
for (let option of select ) {
store.push(option.text);
}
// resets the last selected option's text back to it's default value
function reset() {
Array.prototype.map.call(select, option => {
for(let text of store) {
if(text.toUpperCase() == option.text) option.text = text;
}
});
}
// add the handler function for each time the select option is changed
select.addEventListener("change", function (e) {
if(this.selectedIndex == -1 ) return;
reset();
for( let selected of this.selectedOptions ) {
selected.text = selected.text.toUpperCase();
}
});
<select>
<option></option>
<option>Some text</option>
<option>Some text</option>
<option>Some text</option>
</select>