Click here to Skip to main content
15,900,906 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
How to get value from a hidden field from javascript.
I m using the below code to do this but getting error:-
JavaScript
var digiclock = document.getElementById("<%= HiddenFieldMinutes.ClientID %>").value;


I m getting this error message : Unable to get value of the property 'value': object is null or undefined

Please guide me that how i get value from this hidden field in JavaScript.
Posted
Comments
pradiprenushe 11-Jul-12 5:34am    
Check these cases:
1. Check hidden field present
2. Check hidden field container, whether it is inside some other control

Rewrite your statement in following way...

C#
if($find("<%=HiddenFieldMinutes.ClientID%>")== null)
    alert('Hidden Field is not found');
else
var digiclock = $get('<%= HiddenFieldMinutes.ClientID %>').value;
 
Share this answer
 
Hi,
You have to check the following:
1. Check hidden field present.
2. Whether you are writing javascript in separate JS file.
If you are are writing javascript in separate JS file then you cannot get client id directly there.

Just follow the steps:
1. Add the attribute in page load for hidden field.
C#
YourBtn.Attributes.Add("onclick", "return YourFunction('" + HiddenFieldMinutes.ClientID + "')");


2. write the javascript function as follows:
JavaScript
function test(HdnFldID) {
   var digiclock = document.getElementById(HdnFldID).value;
}


All the best.
--Amit
 
Share this answer
 
Use below format for getting the value of Hidden field

var digiclock = document.getElementById('HiddenFieldMinutes').value
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900