Input Search name Property - Change the name of a search field: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Search

Description

Input Search name Property - Change the name of a search field:

Demo Code

ResultView the demo in separate window

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

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

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

function change() {//from   ww  w .  j  a v a2s.  co  m
    var x = document.getElementById("mySearch").name = "newSearchName";
    console.log("The name was changed to: " + x);
}
</script>

</body>
</html>

Related Tutorials