The Input Hidden value property in HTML DOM is used to set or return the value of the value attribute of the hidden input field. The value attribute defines the default value of the input hidden field.
Syntax:
- It returns the value property.
hiddenObject.value
- It is used to set the value property.
hiddenObject.value = text
Property Values: This property contains single value text which is used to specify the initial value of the input hidden field. Return Value: It returns a string value which represent the value of the value attribute of the hidden input field.
Example 1: This example illustrates how to return the hidden value property.
html
<!DOCTYPE html>
< html >
< head >
< title >
HTML DOM Input Hidden value Property
</ title >
</ head >
< body style = "text-align:center;" >
< h1 style = "color:green;" >
GeeksForGeeks
</ h1 >
< h2 >DOM Input Hidden value Property</ h2 >
< input type = "hidden" id = "GFG"
value = "GeeksForGeeks" >
< button onclick = "myGeeks()" >
Submit
</ button >
< p id = "sudo" style = "color:green;font-size:35px;" ></ p >
< script >
function myGeeks() {
var x = document.getElementById("GFG").value;
document.getElementById("sudo").innerHTML = x;
}
</ script >
</ body >
</ html >
|
Output: Before clicking on the button :
After clicking on the button:
Example 2: This example illustrate how to set the hidden property.
html
<!DOCTYPE html>
< html >
< head >
< title >
HTML DOM Input Hidden value Property
</ title >
</ head >
< body style = "text-align:center;" >
< h1 style = "color:green;" >
GeeksForGeeks
</ h1 >
< h2 >DOM Input Hidden value Property</ h2 >
< input type = "hidden" id = "GFG" value = "GeeksForGeeks" >
< button onclick = "myGeeks()" >
Submit
</ button >
< p id = "sudo" style = "color:green;font-size:20px;" ></ p >
< script >
function myGeeks() {
var x = document.getElementById("GFG").value
= "Sudo Placement";
document.getElementById("sudo").innerHTML
= "The value of the value attribute"
+ " have changed to " + x;
}
</ script >
</ body >
</ html >
|
Output:
Before clicking on the button:
After clicking on the button:
Supported Browsers: The browser supported by DOM input Hidden value Property are listed below:
- Google Chrome 1
- Edge 12
- Firefox 1
- Opera 2
- Safari 1
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
24 Aug, 2022
Like Article
Save Article