Javascript examples for DOM HTML Element:Select
The name property sets or gets the name attribute of a drop-down list.
Set the name property with the following Values
Value | Description |
---|---|
name | Sets the name of the drop-down list |
A String, representing the name of the drop-down list
The following code shows how to return the value of the name attribute of a drop-down list:
<!DOCTYPE html> <html> <body> <form> <select name="selectName" id="mySelect"> <option>CSS</option> <option>HTML</option> <option>SQL</option> <option>Javascript</option> </select>//from w w w. j a v a 2 s.com </form> <button onclick="display()">Display name</button> <button onclick="change()">Change name</button> <script> function display() { var x = document.getElementById("mySelect").name; console.log("The name of the dropdown list is: " + x); } function change() { var x = document.getElementById("mySelect").name = "newName"; console.log("The name was changed to: " + x); } </script> </body> </html>