Input Text name Property - Change the name of a text field: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

Input Text name Property - Change the name of a text field:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>
Username: <input type="text" id="myText" name="usrnm">

<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>

<script>
function display() {
    var x = document.getElementById("myText").name;
    console.log("The name of the text field is: " + x);
}

function change() {//w w w .ja  v a 2  s.c om
    var x = document.getElementById("myText").name = "username";
    console.log("The name was changed to: " + x);
}
</script>

</body>
</html>

Related Tutorials