Main Tutorials

How to get hidden field value in JavaScript

In JavaScript, you can use following two ways to get hidden field value in a form :

  1. document.getElementById(‘hidden field id’).value
  2. document.formName.elements[‘hidden field name’].value

See an example here…


<html>
<body>

<script type="text/javascript">
function printIt(){
   alert(document.getElementById('abcId').value);
   alert(document.formName.elements['abcName'].value);
}
</script>

<h1>Access Hidden value in JavaScript</h1>
<form name="formName">
	<input type=hidden id="abcId" name="abcName" 
                  value="Wall Street! Money Never Sleep"/>

	<input type=button value="Get Value" onclick="printIt()" />
</form>

</body>
</html>

If the button is clicked, it will prompts the hidden field value “Wall Street! Money Never Sleep”.

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
11 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Alvaro
11 years ago

Hello,

Man, you don’t know how many times your site helped me.
Thank you again and keep the good work!

e?ek
11 years ago

afferim lan s?pa

MerlinNZ
9 years ago

It is better practice to use something like this.

document.getElementById(”).value

This way it will work if you use Master Pages as well.

Balaji
11 years ago

Thanks for all the post dude ! ! !

Smithb288
5 years ago

Heya im for the first time the following. I discovered this specific table as a consequence I to discover The item faithfully of use &amp the idea rallied round myself publicized lots. I am hoping to deliver a little back again furthermore foster further like so adaebkeebkkddbbf

Sourabh
11 years ago

Hi mkyong,
This tutorial is very help but can you tell me how can i get an array of all input type elements on jsp in javascript.My elements are created dynamically.

priyantha
11 years ago

Thanks. your sites are very usefull every time

Balaji
11 years ago

Thanks dude

ganeshkumar.t
11 years ago

Hi , Do you have any suggestion on huge data transfer
I have very large XML’s to be transfered from offline to online server.
I idea is to apply some shrinking logic and make the xml shrink and send across,.
Can you guide me on your brain thoughts to carry out a safe and easy data transfer.
Regards
Ganesh

SIddhant
11 years ago

If one checkbox is disbaled how to get the value checkbox in backingbean in jsf without using valueChangeListener …

BRH
11 years ago

Thank’s for this post!