ReadOnly does not work

-1

When I include an item dynamically in table , I want to leave the cbempresa field with readonly=true and when I have no items in table it needs to be readonly=false , logic works when I use disabled , but% with% do not. Here's how I'm doing:

$("#cbempresa").prop("readonly", true);

And here is to remove readonly :

  $("#cbempresa").prop("readonly", false)

I thought it was something I was doing wrong, but putting readonly works.

    
asked by anonymous 14.11.2018 / 18:09

1 answer

5

The <select> element (as in the case of its #cbempresa element) does not have the readonly attribute, see here:

  

< select > HTML Element - Attributes

And the readonly attribute does not receive a value true or false , if it is present, the element is read-only, if it is not present it is not, see here:

  

What is the difference between readonly="true" & readonly="readonly"? - Stack Overflow

See example below, the field nascimento is not read-only and the idade field is read-only:

<input type="text" id="nascimento" name="nascimento">
<input type="text" id="idade" name="idade" readonly>

EDITION

As mentioned in the comments (Sam and Caique Romero), there are some alternatives to simulating readonly behavior in a <select> element, see here:

  

How to apply readonly in a select? - Stack Overflow in English

    
14.11.2018 / 18:34