The required
property sets or gets
whether a radio button must be filled before submitting a form.
required |
Yes | 10.0 | Yes | Yes | Yes |
Return the required property.
var v = radioObject.required
Set the required property.
radioObject.required=true|false
Value | Description |
---|---|
true|false | Set whether a radio button should be checked before submitting a form
|
A Boolean type value, true if the radio button must be checked before submitting a form, otherwise false.
The following code shows how to set a radio button to be a required part of form submission.
<!DOCTYPE html>
<html>
<body>
<!-- w w w .jav a 2 s. c om-->
<form action="url">
Radio Button: <input type="radio" id="myRadio" name="test">
<input type="submit">
</form>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myRadio").required = true;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to check if a radio button must be checked before submitting a form.
<!DOCTYPE html>
<html>
<body>
<!-- w w w .jav a 2s . com-->
<form action="url">
Radio Button: <input type="radio" id="myRadio" name="test" required>
<input type="submit">
</form>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myRadio").required;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: