Change the value of the name attribute of a drop-down list:
document.getElementById("mySelect").name = "newName";
Click the buttons below to display and change the value of the name attribute of the drop-down list.
<!DOCTYPE html> <html> <body> <form> <select name="selectName" id="mySelect"> <option>Apple</option> <option>Pear</option> <option>Banana</option> <option>Orange</option> </select> </form>//w w w . j av a2 s . c om <p id="demo"></p> <button onclick="display()">Display name</button> <button onclick="change()">Change name</button> <script> function display() { var x = document.getElementById("mySelect").name; document.getElementById("demo").innerHTML = "The name of the dropdown list is: " + x; } function change() { var x = document.getElementById("mySelect").name = "newName"; document.getElementById("demo").innerHTML = "The name was changed to: " + x; } </script> </body> </html>