HTML DOM Input Text name Property

HTMLWeb DevelopmentFront End Technology

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.

Syntax

Following is the syntax for −

Setting the name property −

textObject.name = name

Here, name is for specifying the text field name.

Example

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

Live Demo

<!DOCTYPE html>
<html>
<body>
<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>
<script>
   function changeName() {
      document.getElementById("USR").name ="NEW_USER" ;
      document.getElementById("Sample").innerHTML = "Text field name is now NEW_USER";
   }
</script>
</body>
</html>

Output

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

On clicking the CHANGE NAME button −

raja
Published on 19-Aug-2019 12:24:03
Advertisements