HTML DOM Input Search name Property
The Input Search name Property in HTML DOM is used to set or return the value of the name attribute of a search field. The name attribute is required for each input field. If the name attribute is not specified in an input field then the data of that field would not be sent at all.Â
Syntax:Â
- It returns the Input search name property.
searchObject.name
- It is used to set the Input search name property.
searchObject.name = name
Property Values: It contains a single value name which defines the name of the search field.Â
Return Value: It returns a string value which represents the name of the search field.Â
Example 1: This example returns the Input search name property.Â
html
<!DOCTYPE html>
< html >
< head >
< title >
HTML DOM Input Search name Property
</ title >
</ head >
< body style = "text-align: center;" >
< h1 >GeeksforGeeks</ h1 >
< h2 >HTML DOM Input Search name Property</ h2 >
< form id = "myGeeks" >
< input type = "Search" id = "test"
name = "myGeeks"
placeholder = "Type to search..." >
</ form >
< br >
< button onclick = "myGeeks()" >
click here
</ button >
< p id = "result" >
</ p >
< script >
function myGeeks() {
// return input search name property
let inputName =
document.getElementById("test").name;
document.getElementById("result")
.innerHTML = inputName;
}
</ script >
</ body >
</ html >
|
Output:Â
Example 2: This example illustrates how to set the Input Search name Property.Â
html
<!DOCTYPE html>
< html >
< head >
< title >
HTML DOM Input Search name Property
</ title >
</ head >
< body style = "text-align: center;" >
< h1 >GeeksforGeeks</ h1 >
< h2 >HTML DOM Input Search name Property</ h2 >
< form id = "myGeeks" >
< input type = "Search" id = "test" name = "myGeeks"
placeholder = "Type to search..." >
</ form >
< br >
< button onclick = "myGeeks()" >
Click Here
</ button >
< p id = "result" ></ p >
< script >
function myGeeks() {
// setting input search name property
let searchName = document.getElementById("test")
.name = "HelloGeeks";
document.getElementById("result").innerHTML
= "The value of name attribute changed to "
+ searchName;
}
</ script >
</ body >
</ html >
|
Output:Â
Supported Browsers:
- Google Chrome 5 and above
- Edge 12 and above
- Firefox 4 and above
- Opera 10.6 and above
- Safari 5 and above
Last Updated :
02 Jan, 2024
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...