Easy Tutorial
❮ Obj Navigator Met Win Postmessage ❯

Radio name Attribute


Definition and Usage

The name attribute sets or returns the name of a radio button.

Tip: Radio buttons with the same name attribute belong to the same group.

The name attribute is used for sending data to the server after form submission or for referencing form data in JavaScript.

Note: Only form elements with a name attribute will have their values passed when submitting a form.

Syntax

Set the name attribute:

Return the name attribute:


Browser Support

All major browsers support the name attribute.


Example

Display the name attribute value of the "Red" radio button:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>tutorialpro.org(tutorialpro.org)</title>
<script>
function displayResult(){
    var x=document.getElementById("red").name;
    alert(x);
}
</script>
</head>
<body>

<form>
Which color do you prefer?<br>
<input type="radio" name="colors" id="red">Red<br>
<input type="radio" name="colors" id="blue">Blue<br>
<input type="radio" name="colors" id="green">Green
</form>
<button type="button" onclick="displayResult()">Display the name of the Red radio button</button>

</body>
</html>

❮ Obj Navigator Met Win Postmessage ❯