0

What am trying to do is something like this

$('input[type="text"],input[type="checkbox"],textarea').not(data-value="SHControl").attr('readonly','readonly');

Please provide me the correct syntax to achieve the same.

furkle
  • 5,019
  • 1
  • 15
  • 24
raj
  • 3
  • 2

4 Answers4

1

I think what you're looking for is the syntax for using .not in jQuery. What you want to do is this:

$('input[type="text"],input[type="checkbox"],textarea').not('[data-value=SHControl]').attr('disabled', 'disabled');

Created a jsfiddle here to show how it works: https://jsfiddle.net/clausjensen/e24seukm/

Claus
  • 1,975
  • 18
  • 24
0

$('input[type="text"],input[type="checkbox"],textarea').each(function() {
  var el = $(this);

  el.prop("readonly", el.data("value") !== "SHControl");
})
*[readonly] {
  border: solid 1px red
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" />
<input type="text" data-value="SHControl" />
<textarea></textarea>

A checkbox has no readonly state as this only prevents the manipulation of the value attribute -> Can HTML checkboxes be set to readonly?

Community
  • 1
  • 1
Andreas
  • 21,535
  • 7
  • 47
  • 56
0

hello this the solution of added readonly

 <style>
    *[readonly] {
  border: solid 1px red
}
    </style>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
 <script type="application/javascript">
 $(document).ready(function(e) {

    $('.test').each(function(index, element) {

        if($(this).attr('data-value')!="SHControl"){
            $(this).attr('readonly','readonly');
        }
    });
});
 </script>


 <input class="test" type="text" data-value="SHControl"/>
 <input class="test" type="checkbox" data-value="SHControl"/>

 <textarea class="test" data-value="SHControl" ></textarea>

 <input class="test" type="text" data-value="SHControl1"/>
 <input class="test" type="checkbox" data-value="SHControl1"/>

 <textarea class="test" data-value="SHControl1" ></textarea>
Jydipsinh Parmar
  • 484
  • 5
  • 14
0

Correct syntax is:

$("input[type='text'], input[type='checkbox'], textarea").not("input[data-value='SHControl']").attr("readonly", "readonly");
ozgrozer
  • 1,824
  • 1
  • 23
  • 35