HTML DOM Input Search name Property

HTMLWeb DevelopmentFront End Technology

The HTML DOM Input Search name property is used for setting or returning the name attribute of a reset button. The name attribute helps in identifying the form data after it has been submitted to the server. JavaScript can also use the name attribute to refer form elements for manipulating later on.

Syntax

Following is the syntax for −

Setting the name property −

searchObject.name = name

Here, name is for specifying the search field name.

Example

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

<!DOCTYPE html>
<html>
<body>
<h1>Input search name Property</h1>
<form>
FRUITS: <input type="search" id="SEARCH1" name="fruits" maxlength="5">
</form>
<p>Change the name of the above search field by clicking the below button</p>
<button type="button" onclick="changeName()">CHANGE NAME</button>
<p id="Sample"></p>
<script>
   function changeName() {
      document.getElementById("SEARCH1").name ="SEARCH_2 ;
      document.getElementById("Sample").innerHTML = "Search field name is now SEARCH_2";
   }
</script>
</body>
</html>

Output

This will produce the following output −

On clicking the CHANGE NAME button −

raja
Published on 19-Aug-2019 09:57:00
Advertisements