HTML DOM Input Hidden name Property

HTMLWeb DevelopmentFront End Technology

The HTML DOM input hidden name property returns and alter the value of name attribute of input field of type=”hidden” in an HTML document.

Syntax

Following is the syntax −

1. Returning name

object.name

2. modifying name

object.name=”text”

Example

Let us see an example of HTML DOM input hidden name property −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   body{
      text-align:center;
      background-color:#F19A3E;
      color:#fff;
   }
   .btn{
      background-color:#3C787E;
      border:none;
      height:2rem;
      border-radius:50px;
      width:60%;
      margin:1rem auto;
      display:block;
      color:#fff;
      outline:none;
   }
   .show{
      color:#fff;
      font-size:1.2rem;
      font-weight:600;
   }
</style>
</head>
<body>
<h1>DOM Hidden name Property Example</h1>
Enter your Name:
<input type="hidden" class="input-field" name="Hi_I'm_hidden_input_field">
<button onclick="getName()" class="btn">Click to get name of hidden input field</button>
<div class="show"></div>
<script>
   function getName() {
      var inputField = document.querySelector(".input-field");
      var msgDiv= document.querySelector(".show");
      msgDiv.innerHTML=inputField.name;
   }
</script>
</body>
</html>

Output

This will produce the following output −

Now, click on “blue” button to get the value of name attribute of hidden input field.


raja
Published on 17-Jul-2019 14:44:16
Advertisements