Javascript DOM HTML Input Radio required Property set

Introduction

Set a radio button to be a required part of form submission:

document.getElementById("myRadio").required = true;

Click the button to set the required property for the radio button.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form action="/action_page.php">
  Radio Button: <input type="radio" id="myRadio" name="test">
  <input type="submit">
</form>// ww w  .j a  v a 2s .c  o  m
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
  document.getElementById("myRadio").required = true;
  document.getElementById("demo").innerHTML = "The required property was set.";
}
</script>

</body>
</html>



PreviousNext

Related