1

I have multiple of textbox...each textbox have own button to enable or disable . How to do it ? I have already try this

$('#disablebutton').click(function(){
$('#textfieldToClose').attr('disable');
});

<input type="text" name="text11" readonly="readonly" id="textfieldToClose">
<input type="button" value="edit" name="button1" id="disablebutton">
Frozen
  • 97
  • 1
  • 4
  • 15
  • possible duplicate of [How to disable/enable an input with jQuery?](http://stackoverflow.com/questions/1414365/how-to-disable-enable-an-input-with-jquery) – fejese Apr 16 '14 at 19:01

3 Answers3

2

Try:

$(document).ready(function(){
    $('#disablebutton').click(function(){
    if($('#textfieldToClose').prop('disabled'))
    {
     $('#textfieldToClose').prop('disabled', false)
    }
    else{
         $('#textfieldToClose').prop('disabled', true)
      }
    });
})

or with Read only:

$(document).ready(function(){
    $('#disablebutton').click(function(){
    if($('#textfieldToClose').prop('readonly'))
    {
     $('#textfieldToClose').removeAttr('readonly');
    }
    else{
         $('#textfieldToClose').attr('readonly', 'readonly')
      }
    });
});

Because you only select the attr but, don't do anything with. Live demo

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Wilfredo P
  • 4,070
  • 28
  • 46
  • hi your demo is work very nice ... but when i do it on my ... still not function – Frozen Apr 16 '14 at 19:06
  • i found the problem ~ by the way thanks you so much ! – Frozen Apr 16 '14 at 19:35
  • sorry now have some question ... how to do this in multiple textbox? because each textbox have own edit button – Frozen Apr 16 '14 at 19:41
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/50816/discussion-between-frozen-and-freak-droid) – Frozen Apr 16 '14 at 19:44
1

Try this:

$('#disablebutton').click(function(){
   $(this).prev().attr("disabled", "disabled"); 
});

Working Demo

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
0
$('#disablebutton').click(function(){
  $('#textfieldToClose').attr('disabled', 'disabled'); //sett the `disabled` attribute on the    element
});

$('#textfieldToClose').attr('disable') did not work because you were just quering an attribute disable on the element which doesn't even exist. The correct name is disabled

Akinkunle Allen
  • 1,299
  • 12
  • 19