UncleCoder.com

UncleCoder.com

Free programming examples and instructions

Remove required attrbute HTML 5 control - Javascript

Demo and code for remove required attribute in HTML control

by Athil


Posted on 27 Jun 2018 Category: Javascript Views: 6404


Here I am going to show how to remove required attribute of text control in HTML using javascript.

DEMO

DOWNLOAD DEMO

document.getElementById('txtid').required = false;

Where 'txtid' is the control id of the textbox which want to remove required attribute.

Full Demo code

HTML

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Demo for add/ Remove Required attribute using javascript</title>
</head>
<body>

    <h1>Demo for add/ Remove Required attribute using javascript </h1>

    <form>
    <input id="txtid"  type="text"/>

    <button type="submit" > Submit </button> <br/><br/>

    <button onclick ="AddRequired();"> Add required </button> 
    <button onclick ="RemoveRequired();"> Remove Required </button>
        </form>
   

  

</body>
</html>

Javascript



        function AddRequired()
        {
            document.getElementById('txtid').required = true;
        }
        function RemoveRequired()
        {
            document.getElementById('txtid').required = false;
        }



 



Leave a Comment:


Click here to register

Popular articles