1

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?

3 Answers 3

2

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/

Sign up to request clarification or add additional context in comments.

Comments

1

You are giving boolean value as String

Use this

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

instead of

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

DEMO

1 Comment

Thank you for your time, appreciated
1

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

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

1 Comment

Thanks for your time all comments have been appreciated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.