How to select a radio button by default
- radio button html - Got some radio buttons and need to set as selected by default when the web page is loaded. How can we do that?
html code :
XHTML code :
- Please note, that the actual value of checked attribute does not actually matter; it's just a convention to assign "checked". Most importantly, strings like "true" or "false" don't have any special meaning.
If we don't aim for XHTML conformance, we can simplify the html code to:
- we can use the html radio checked attribute.
html5 radio button using AngularJS - And actually the normal answer won't work. our html will look pretty similar to the normal radio button:
- In our controller we declared the mValue that is associated with the radio buttons. To have one of these radio buttons preselected, assign the $scope variable associated with the group to the desired
radio button selected :
- This makes the "second" html radio checked on loading the page
Add this attribute to the radio button checked code :