Input Radio required Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Radio

Description

The required property sets or gets whether a radio button must be checked before submitting a form.

This property reflects the HTML required attribute.

Set the required property with the following Values

Value Description
true|false Sets whether a radio button should be checked before submitting a form

Return Value

A Boolean, returns true if the radio button must be checked before submitting a form, otherwise it returns false

The following code shows how to check if a radio button must be checked before submitting a form:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form action="#">
  Radio Button: <input type="radio" id="myRadio" name="test">
  <input type="submit">
</form>//  w w w .j av a2 s.  c  om

<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
    var v = document.getElementById("myRadio").required;
    document.getElementById("demo").innerHTML = v;
}
</script>

</body>
</html>

Related Tutorials