Andrew
Andrew

Reputation: 13

JQuery enabling a textbox with a button event query

I have a tiny issue if anybody can help... I am trying to implement a form, so when the page loads the textbox is disabled. If the user wishes to amend information they first have to press a button which will enable the text box.

<input id="text" type="text" disabled="disabled">
<br />
<button>Enable</button   

So I have a basic textbox which is disabled. Then an event that should enable the textbox...

  <script type="text/javascript" src="jquery.js"></script>   
  <script type="text/javascript">   
     $(document).ready(function(){     
       $("button").click(function(){         
        $("#text").attr("disabled","false");     
       });   
     });   
  </script>  

I can get this working when the textbox is not initially disabled and I want to disable it, though I can not get it working the other way round - when it is disabled and I want to enable it.

Can anyone point me in the right direction?

Upvotes: 1

Views: 697

Answers (3)

mayank sharma
mayank sharma

Reputation: 63

Or you can use this, Even the last answer by Mr Soni is correct.

$(document).ready(function(){     
   $("button").click(function(){         
    $("#text").prop('disabled', false);     
   });   
 });

Upvotes: 1

Mritunjay
Mritunjay

Reputation: 25892

You are giving boolean value as String

Use this

$("#text").attr("disabled",false);  

instead of

$("#text").attr("disabled","false");

DEMO

Upvotes: 1

Devendra Soni
Devendra Soni

Reputation: 1934

Hi i have created a jsfiddle for you see the working example...

you should use removeAttr instead of attr code:-

 $(document).ready(function(){     
       $("button").click(function(){         
        $("#text").removeAttr("disabled");     
       });   
     });   

link:-http://jsfiddle.net/L7S37/15/

Upvotes: 2

Related Questions