How to enable/disable button/dropdown using DOM/JavaScript.

One of the most and highly used DOM component is - "document".
In this example we are going to cover how to use the DOM object and we are going to disable/enable the HTML button and dropdown.
Let's write the sample HTML code which has the button and the dropdown element.

disableButton.html

<html>
   <head>
      <script src = "test.js"></script>
   </head>
   <body style="background-color:#F2F2F2;">
      <button id="btn01">OK</button>
      <button onclick="disableElement()">Disable</button>
      <button onclick="enableElement()">Enable</button>
      
      <select id="mySelect">
         <option>Java</option>
         <option>.Net</option>
         <option>PHP</option>
         <option>JavaScript</option>
      </select>
      
      <input type="button" onclick="disable()" value="Disable list" />
      <input type="button" onclick="enable()" value="Enable list" />
   </body>
</html>

Now that we are done with the sample HTML, let's write the JavaScript functions which will enable and disable the button and dropdown element.

test.js

function disableElement() {
    document.getElementById("btn01").value = "Disabled";
    document.getElementById("btn01").disabled = true;
}

function enableElement() {
    document.getElementById("btn01").value = "OK";
    document.getElementById("btn01").disabled = false;
}

function disable() {
    document.getElementById("mySelect").disabled = true;
}

function enable() {
    document.getElementById("mySelect").disabled = false;
}
 
The browser will render the above code something like this.
 

 

73 comments:

  1. JavaScript is the language future. The new JavaScript Version (Ecmascript 6) has been relaeased.

    JavaScript Online Training

    Javascript Online Training

    ReplyDelete
  2. Thanks for your Blog i thinking is very useful.Any one want Learn the Java Training in Chennai.

    Thanks For sharing...Any one want Learn the Java Training in ChennaiJava Course Training

    Thanks For sharing...Any one want Learn the Java Training in ChennaiJ2EE Course Training

    ReplyDelete
  3. Thanks for your sharing to spread out your knowledge<a href="http://www.trainingintambaram.net/j2ee-training-in-chennai/>J2EE Training in Chennai</a>

    ReplyDelete
  4. Thanks for your sharing to spread out your knowledgeJ2EE Training in Chennai

    ReplyDelete
  5. Hello,
    Nice blog very well defined stuff you given thanks for sharing. Here i am also Sharing Information on Java 2 Platform Enterprise Edition Training. It will Definately useful for Everyone.

    ReplyDelete
  6. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information. Java Training in Chennai

    ReplyDelete
  7. Excellent piece of information, I had come to know about your website,i have read some posts of yours by now, and let me tell you, your site gives the best and the most interesting information.Java is a dynamic programming language specially designed for use in the assigned environment of the InternetReadmore..

    ReplyDelete
  8. Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.

    Data Science Training in Chennai
    Data science training in bangalore
    Data science online training
    Data science training in pune
    Data science training in kalyan nagar
    Data Science with Python training in chenni

    ReplyDelete
  9. hi, nice information is given in this blog. Thanks for sharing this type of information, it is so useful for me. nice work keep it up. best sap simple finance online training institute in hyderabad


    ReplyDelete
  10. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information. 
    Python training in usa
    Python training in marathahalli
    Python training in pune

    ReplyDelete
  11. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
    DevOps online Training
    DevOps Training in USA

    ReplyDelete
  12. I love the blog. Great post. It is very true, people must learn how to learn before they can learn. lol i know it sounds funny but its very true. . .


    angularjs Training in bangalore

    angularjs Training in btm

    angularjs Training in electronic-city

    angularjs Training in online

    angularjs Training in marathahalli

    ReplyDelete
  13. Your new valuable key points imply much a person like me and extremely more to my office workers. With thanks from every one of us.

    Best AWS Training in Chennai | Amazon Web Services Training in Chennai

    AWS Training in Bangalore | Amazon Web Services Training in Bangalore

    Amazon Web Services Training in Pune | Best AWS Training in Pune


    Your new valuable key points imply much a person like me and extremely more to my office workers. With thanks from every one of us.

    ReplyDelete
  14. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
    python training in pune
    python training institute in chennai
    python training in Bangalore

    ReplyDelete
  15. Great content thanks for sharing this informative blog which provided me technical information keep posting.
    Blueprism training in Pune

    Blueprism training in Chennai

    ReplyDelete
  16. Thanks for such a great article here. I was searching for something like this for quite a long time and at last I’ve found it on your blog. It was definitely interesting for me to read about their market situation nowadays. Well written article Thank You for Sharing with Us pmp training Chennai | pmp training centers in Chenai | pmp training institutes in Chennai | pmp training and certification in Chennai | pmp training in velachery |

    ReplyDelete
  17. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information. 
    Authorized iphone service center in Chennai | iphone service center in chennai | Mobile service center in chennai | Authorized iphone service center in Chennai | iphone service center in chennai

    ReplyDelete
  18. The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea.
    here by i also want to share this.
    data science online training
    python online training
    uipath online training
    data science with python online training
    rpa online training

    ReplyDelete
  19. I am sure this post has helped me save many hours of browsing other related posts just to find what I was looking for. Many thanks!

    Microsoft Azure online training
    Selenium online training
    Java online training
    Java Script online training
    Share Point online training


    ReplyDelete
  20. Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    Microsoft Azure online training
    Selenium online training
    Java online training
    uipath online training
    Python online training

    ReplyDelete
  21. Very helpful Post!!! This is the first time I have read a post like this. Find Career tips here.

    Apple iPhone Service Center in Chennai Anna Nagar


    ReplyDelete
  22. Quickbooks is mostly used accounting software in the world because it is work in large & small scale business companies. If you are already used this software or facing any issue. Dial our toll free number Quickbooks Proadvisor Support Phone Number 1-800-986-4607 for fast & instant solution.

    ReplyDelete
  23. Such great information for blogger iam a professional blogger thanks…

    Get Business Analyst Training in Bangalore from Real Time Industry Experts with 100% Placement Assistance in MNC Companies. Book your Free Demo with Softgen Infotech.

    ReplyDelete
  24. Hey! Amazing content. I love your blog. Recently I have started using QuickBooks software for my business. I love the ease and different tools provided by this software. I highly recommend others to use QuickBooks software for their business. You can get instant help and support at QuickBooks Support Phone Number Florida 1-833-401-0204. Read more: https://tinyurl.com/vz56e5v OR visit: https://www.qb-dataservices.com/quickbooks-in-florida/

    ReplyDelete
  25. Well explained and knowledgeable blog click here for QuickBooks support number for more detail dial on our QuickBooks Support phone number 844-908-0801

    ReplyDelete
  26. Well explained and knowledgeable blog click here for QuickBooks customer service number for more detail dial on our QuickBooks Support phone number 844-908-0801

    ReplyDelete
  27. This comment has been removed by the author.

    ReplyDelete
  28. Nice Blog ! Stop your search here if you are looking for help to get your QuickBooks issues resolved. Our QuickBooks Customer Service Number 1-855-9O7-O4O6 is meant to help customers with reliable solutions.

    ReplyDelete
  29. Nice & Informative Blog ! Are You facing issue in QuickBooks? We resolve all sorts of issues with effective solutions provided by our QuickBooks experts. Just give a call on QuickBooks Customer Service Number 1-855-907-0406.

    ReplyDelete
  30. This information is really awesome thanks for sharing most valuable information. Best Angular Online Training in Pune, Mumbai, Delhi NCR

    ReplyDelete
  31. Very nice article, thanks for the information. Best Digital Marketing Agency in Chennai offering Growth Strategies for Business. ✔️6+ Yrs. Industry Exp. ✔️Certified Professionals. ☎️ 8608954456
    Amazon product listing services

    ReplyDelete
  32. I have to search sites with relevant information on given topic and provide them to teacher our opinion and the article.Thanks for the well-written post and I will follow your updates regularly and this is really helpful. Keep posting more like this.This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.
    Data Science Training In Chennai

    Data Science Online Training In Chennai

    Data Science Training In Bangalore

    Data Science Training In Hyderabad

    Data Science Training In Coimbatore

    Data Science Training

    Data Science Online Training



    ReplyDelete
  33. This Article is Worth of sharing. The information is helpful for sure! Keep going like this!
    Linux VPS Hosting

    ReplyDelete
  34. Amid uncertainty over coronavirus lockdown, we at QuickBooks Customer Service Phone Number 1-855-662-2O4O still provide 24/7 reliable assistance. All the queries related to QuickBooks will be answered by our QuickBooks experts.

    https://tinyurl.com/yy33sxqb

    ReplyDelete



  35. Nice article and thanks for sharing with us. Its very informative



    AI Training in Hyderabad

    ReplyDelete
  36. https://zulqarnainbharwana.com/laurence-fox/

    ReplyDelete


  37. Nice article and thanks for sharing with us. Its very informative


    AI Training in Hyderabad

    ReplyDelete
  38. Need comprehensive support while accessing QuickBooks? If that’s the case, simply make a direct call at our QuickBooks Support Phone Number +1(844)233-3033, and acquire instantaneous assistance to our clients. Our experts are skilled enough to answer all of the error codes users have.
    https://tinyurl.com/y98zjer5
    https://tinyurl.com/y8la4op8
    https://bit.ly/2MmDiEl
    https://bit.ly/34TrDmJ

    ReplyDelete
  39. Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep update your blog and Keep always sharing with us. In this Blog, we use to cover to use the DOM object and we disable/enable the HTML button and dropdown. I liked this information. Are you want to know information about to USA VPS Server Hosting? then you choose the right option on Onlive Server then can get you the best information about to USA VPS Server Hosting.

    ReplyDelete
  40. Set An Alert For USD TO INR FORECAST To Receive An Email When The Exchange Rate Changes. Alternatively, Bookmark The Page And Check Back Here Regularly.

    ReplyDelete
  41. Very Informative blog thank you for sharing. Keep sharing.

    Best software training institute in Chennai. Make your career development the best by learning software courses.

    cloud computing training in chennai
    devops training in chennai
    uipath training in chennai

    ReplyDelete
  42. Needed to compose you a very little word to thank you yet again
    regarding the nice suggestions you’ve contributed here.
    node js training in chennai
    oracle training in chennai

    ReplyDelete
  43. Great tips and very easy to understand. This will definitely be very useful for me when I get a chance to start my blog.
    data science course fee in hyderabad

    ReplyDelete
  44. Самые важные средства ворожбы появились тысячелетия тому назад до Н.Э. Вернется ли муж в семью гадание считается максимально вероятным вариантом нагадать грядущее личности. Синоптичные явления или церемониальные убийства животных с течением времени составили точное разъснение обнаруженного.

    ReplyDelete
  45. This is the first time I visit here. I found such a large number of engaging stuff in your blog, particularly its conversation. From the huge amounts of remarks on your articles, I surmise I am by all accounts not the only one having all the recreation here! Keep doing awesome. It has been important to compose something like this on my site and you have given me a thought.
    business analytics course in hyderabad

    ReplyDelete
  46. Thank you for sharing this valuable information with us.
    Jewellery ERP Software Dubai
    Jewellery ERP Software Dubai

    ReplyDelete
  47. Hello Blogger,
    This article provides a concise and practical guide on how to enable/disable buttons and dropdowns using DOM and JavaScript. It offers a clear example with sample HTML and JavaScript code, making it easy for developers to implement this functionality in their web applications. Thank you for sharing this useful resource!
    Data Analytics Courses in Nashik

    ReplyDelete
  48. Dear Blogger,
    This is an excellent resource for developers looking to enhance user interactivity on their web pages. It provides practical and actionable guidance for working with DOM and JavaScript, and the clear presentation adds to its value. Found this really useful.
    Data Analytics Courses In Dubai

    ReplyDelete
  49. thank you so much for this wonderful tutorial on how to enable and disable dropdown. I was having this issue while editing my website but gladly I found your blog. It was so helpful.
    Visit - Data Analytics Courses in Delhi

    ReplyDelete
  50. I appreciate the clarity of your explanations and the inclusion of actual source code examples.
    Digital marketing courses in illinois

    ReplyDelete
  51. The seamless flow of ideas and engaging writing style make it easy to stay immersed in the content. Thank you to the author for their remarkable work.
    Data analytics framework

    ReplyDelete