/

HTML / CSS / JavaScript Tutorial

HTML Standard attribute: checked

[this page | pdf | back links]

The HTML checked attribute specifies that the (sub)-element should be pre-selected (i.e. ‘checked’) when the page first loads. It applies to <input> elements (if type = checkbox or type = radio). It also applies to <menuitem> elements (but these are not currently supported by many browsers)

 

Valid attribute values (when used with an <input> element) include:

 

Value

Description

checked

Sub-element should be pre-selected

 

Valid attribute values (when used with a <menuitem> element) include:

 

Value

Description

checked

Indicates that command/menu item should be checked when page loads. Only applies to type = radio or type = checkbox

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body>
Created using HTML:<br>
<form action="http://www.nematrian.com/ExpressionEvaluator.aspx">
<input type="radio" name="expr" value="3*5">3*5</input><br>
<input checked type="radio" name="expr" value="5*exp(1)*max((1,2,3))">5*exp(1)*max((1,2,3))</input><br>
<input type="submit" value="Go to webpage to evaluate">
</form>

<br><br>Created using JavaScript:<br>
<span id="element"></span>

<script>
var f = document.createElement("FORM");
f.setAttribute("action","http://www.nematrian.com/ExpressionEvaluator.aspx");
var x1 = document.createElement("INPUT");
x1.setAttribute("type","radio");
x1.setAttribute("name","expr");
x1.setAttribute("value","3*5");
var txt1 = document.createTextNode("3*5");
var x2 = document.createElement("BR");
var x3 = document.createElement("INPUT");
x3.setAttribute("type","radio");
x3.setAttribute("checked","checked");
x3.setAttribute("name","expr");
x3.setAttribute("value","5*exp(1)*max((1,2,3))");
var txt3 = document.createTextNode("5*exp(1)*max((1,2,3))");
var x4 = document.createElement("BR");
var x5 = document.createElement("INPUT");
x5.setAttribute("type","submit");
x5.setAttribute("value","Go to webpage to evaluate");
f.appendChild(x1);
f.appendChild(txt1);
f.appendChild(x2);
f.appendChild(x3);
f.appendChild(txt3);
f.appendChild(x4);
f.appendChild(x5);
document.getElementById("element").appendChild(f);
</script>

</body>
</html>


NAVIGATION LINKS
Contents | Prev | Next | HTML Attributes


Desktop view | Switch to Mobile