Input Search name Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Search


The name property sets or gets the name attribute of a search field.

Set the name property with the following Values

Value Description
name Sets the name of the search field

Return Value

A String, representing the name of the search field

The following code shows how to get the name of a search field:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
Search: <input type="search" id="mySearch" name="googlesearch">

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

function display() {
    var x = document.getElementById("mySearch").name;
    console.log("The name of the search field is: " + x);

function change() {// w w w .  ja  v  a  2 s .c o  m
    var x = document.getElementById("mySearch").name = "newSearchName";
    console.log("The name was changed to: " + x);


Related Tutorials