Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM Input Text name property

Input Text name property

Input Text Object Reference The Input Text object

Example

Get the name of the text field:

var x = document.getElementById("myText").name;

x The output is:

fname

Try it »


Definition and Usage

The name property sets or returns the name of the text field.

The name property is used to identify the form data submitted to the server, or to reference the form data on the client side through JavaScript.

Note: Only form elements with the name property set can pass their values when the form is submitted.


Browser support

Internet Explorer Firefox Opera Google Chrome Safari

All major browsers support the name property.


Syntax

Return the name attribute:

textObject

.name

Set the name attribute:

textObject

.name=

name

Attribute values

Value Description
name Specifies the name of the text field

Technical details

Return Value: String, representing the name of the text field

More examples

Example

Modify the name of the text field:

document.getElementById("myText").name = "username";

Try it »

Related pages

HTML Reference Manual: HTML name attribute


Input Text Object Reference The Input Text object