Disable Inputs with HTML, JavaScript, and jQuery

In this post we learn how to disable input elements with HTML, JavaScript, and jQuery. With JavaScript and jQuery we can modify the disabled attribute to disable/enable elements when needed.

Using HTML

To disable an input using HTML all we need to do is add the disabled attribute to our input element.


Using JavaScript

To disable an input element using JavaScript we access the disabled property on the element and set it accordingly.

// disable element so it is greyed out and not editable
document.getElementById("element_id").disabled = 'disabled';

// enable element so input element is editable
document.getElementById("element_id").disabled = '';

Using jQuery

To disable input elements using jQuery we use the “.prop” jquery function to set the disabled attribute.

// disable element so it is greyed out and not editable
$( '#element_id' ).prop( 'disabled', 'disabled' );

// enable element so input element is editable
$( '#element_id' ).prop( 'disabled', '' );

Links

YouTube Video

Code on GitHub

Live Example

That is going to do it for this post! Leave any comments/questions/concerns below and thanks for stopping by the blog!

18 comments

  1. You actually make it seem really easy with your presentation but I in finding this matter
    to be actually something which I believe I’d by no means understand.

    It kind of feels too complicated and very vast for me.
    I am taking a look forward for your next publish, I will try to get
    the grasp of it! Escape room lista

  2. whoah this weblog is magnificent i really like studying your articles.
    Keep up the great work! You realize, many individuals are looking around for
    this info, you can help them greatly.

  3. Next time I read a blog, I hope that it doesn’t disappoint me just as much as this one. I mean, I know it was my choice to read, however I truly thought you’d have something interesting to say. All I hear is a bunch of complaining about something that you can fix if you weren’t too busy seeking attention.

  4. It’s nearly impossible to find educated people in this particular subject, but you sound like you know what you’re talking about! Thanks

  5. Spot on with this write-up, I honestly believe that this website needs far more attention. I’ll probably be returning to read more, thanks for the info.

  6. Hi there! I simply wish to offer you a huge thumbs up for your excellent information you’ve got right here on this post. I am coming back to your website for more soon.

  7. An outstanding share! I have just forwarded this onto a coworker who had been conducting a little homework on this. And he actually bought me dinner due to the fact that I found it for him… lol. So let me reword this…. Thank YOU for the meal!! But yeah, thanx for spending time to discuss this subject here on your web site.

  8. Aw, this was a very nice post. Taking the time and actual effort to make a really good article… but what can I say… I procrastinate a whole lot and don’t seem to get anything done.

  9. Aw, this was an exceptionally nice post. Taking the time and actual effort to generate a good article… but what can I say… I hesitate a lot and never seem to get anything done.

  10. I’m impressed, I must say. Rarely do I come across a blog that’s both educative and amusing, and without a doubt, you have hit the nail on the head. The issue is something that not enough folks are speaking intelligently about. I’m very happy that I came across this during my hunt for something relating to this.

  11. Stupa No. 3 was constructed in the course of the time of the Shungas, who also constructed the railing around it as nicely as the staircase.
    Time is just not on your aspect when dealing with water extraction.

  12. Oh my goodness! Awesome article dude! Thank you, However I am experiencing troubles with your RSS. I don’t know the reason why I cannot subscribe to it. Is there anyone else having the same RSS problems? Anybody who knows the solution can you kindly respond? Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *