Explain how to enable and disable an element with JavaScript
Solution
Register enable() and disable() function with buttons toenable and disable text field
<html>
<head>
<title>How to enable or disable input usingJavaScript</title>
</head>
<body>
<h2>Enabling and Disabling text field usingJavaScript</h2>
<form id=”registration-form”> Enter your name: <inputtype=”text” id=”name”> </form>
<button onclick=”disable()”>Disable the textfield</button>
<button onclick=”enable()”>Enable the textfield</button>
<script>
function disable()
{
document.getElementById(“name”).disabled = true;
}
function enable()
{
document.getElementById(“name”).disabled = false;
}
</script>
</body>
</html>