This article will learn how to get the value of a hidden field using the Javascript programming language. You can use two methods to access the DOM and retrieve an element’s value: a hidden field. The two methods are:
First, let’s add a markup that contains HTML hidden field within its content:
<div> <asp:HiddenField ID="myHiddenField" runat="server" Value="learmodo" /> </div>
Now use the Javascript function GetElementById to access the hidden field and retrieve its value:
function GetValueById() { var value; value = document.getElementById("<%= myHiddenField.ClientID %>").value; alert(value); }
Or this function to get the hidden field value by name:
function GetValueByName() { var value; value = document.getElementsByName("myHiddenField")[0].value; alert(value); }
Happy Coding!