Select nameProperty
Select Object
Definition and Usage
The name property sets or returns the name of a drop-down list.
Syntax
Set the name property:
selectObject.name=name
Return the name property:
selectObject.name
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the name property
Example
Example
The following example will alert the name of the drop-down list:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example (example.com)</title>
<script>
function displayResult(){
alert(document.getElementById("mySelect").name);
}
</script>
</head>
<body>
<form>
<select name="mySelect" id="mySelect">
<option>Apple</option>
<option>Pear</option>
<option>Banana</option>
<option>Orange</option>
</select>
</form>
<button type="button" onclick="displayResult()">Display the name of the drop-down list</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Example (example.com)</title>
<script>
function displayResult(){
alert(document.getElementById("mySelect").name);
}
</script>
</head>
<body>
<form>
<select name="mySelect" id="mySelect">
<option>Apple</option>
<option>Pear</option>
<option>Banana</option>
<option>Orange</option>
</select>
</form>
<button type="button" onclick="displayResult()">Display the name of the drop-down list</button>
</body>
</html>
Try it Yourself »
Select Object Other Extensions