Enable disable multiple specific fields

0

Hello everyone As I have no experience with javascript I would like some help of how to enable or disable some expecific fields.

In that Script below and that's exactly what I need only when putting it in the code it disables fields that do not need to be disabled. I would like to know how this code can be changed to just some fields that contain example .. an id = x

 <script type='text/javascript'>//<![CDATA[ 
 $(window).load(function(){
 $(document).ready(function() {
 $("#enable").click(function (){
            // habilita o campo 
    $("input").prop("disabled", false);
    $("select").prop("disabled", false);

 });

 $("#disable").click(function (){
            // desabilita o campo 
    $("input").prop("disabled", true);
    $("select").prop("disabled", true);
});
});
});//]]>  
</script>
<button href="#" id="enable" >Habilita Campos</button>
<button href="#" id="disable" >Desabilita Campos</button>

<input type="text" id="campo" name="campo1" disabled/> <br/>
<input type="text" id="campo" name="campo2" disabled/> <br/>
<input type="text"            name="campo3" disabled/> <!--exemplo Não fazer nada -->   
    
asked by anonymous 10.05.2015 / 15:21

1 answer

1

To disable an input you must use .prop("disabled", true); in a collection of elements.

To create a collection (which can have 1 or more elements) use $('regras de CSS') .

To choose all the inputs you can do as you already have: $('input') . To choose by name: $('input[name="campo2"]') . To choose multiple: $('input[name="campo2"], input[id="campo1"]') .

Example: link

What's missing in your question is how do you know what the input you want to disable is, but I hope that examples help.

    
10.05.2015 / 15:48