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: 138

Edited on 28 Jun 2019

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


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

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

Full Demo code


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

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

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

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

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




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


Leave a Comment: