If clicking something else - change prop / jQuery

334 views Asked by At

if clicking something else, the last input (which was clicked) should be readonly -> true again.

here is my code:

<script>
  $(document).ready(function() {

   $("input").prop("readonly", true);      

   $("input").click(function() { 
        $(this).prop("readonly", false); 
    });

  });
</script>

thanks!

3

There are 3 answers

1
Amin On BEST ANSWER

try this

--to make input editable on click
    $('input').bind('click', function () {
        $(this).prop("readonly", false);
    });

--to make input readonly on lost focus
    $('input').bind('blur', function () {
        $(this).prop("readonly", true);  
    });
0
Arvind Bhardwaj On
$("input").click(function() {
    var $that = $(this);
    $("input").each(function() {
       if ($(this) !== $that) {
          $(this).prop("readonly", false);
       }
    });    
});
0
Liam Allan On

try

$("input").attr("readonly", "readonly");