HTML DOM Input Text name Property

The HTML DOM Input Text name property is used for setting or returning the name attribute of an input text field. The name attribute helps in identifying the form data after it has been submitter to the server.


Following is the syntax for −

Setting the name property − = name

Here, name is for specifying the text field name.


Let us look at an example for the text name property −

Live Demo

<!DOCTYPE html>
<h1>Input Text name Property</h1>
USERNAME: <input type="text" id="USR" name="user_name">
<p>Change the name of the text field by clicking the below button</p>
<button onclick="changeName()">CHANGE NAME</button>
<p id="Sample"></p>
   function changeName() {
      document.getElementById("USR").name ="NEW_USER" ;
      document.getElementById("Sample").innerHTML = "Text field name is now NEW_USER";


This will produce the following output. Only 5 characters are allowed since we have set maxLength 5 −

On clicking the CHANGE NAME button −