Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing hidden field value in javascript

I have a hidden field in my form, I'm setting the hidden field's value on the server and trying to access this value from javascript,

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

If I view the source the hidden field value is set and the ID of the hidden field is the same as the ID I'm calling.

ASPX

            var v = document.getElementById('hxValue').value;
            <asp:HiddenField ID="hxValue" runat="server"/>

VB

            hxValue.Value = "Value1"

I recall doing this before and it should be relatively simple but for some reason, i'm not getting it right.

like image 357
user1835316 Avatar asked May 07 '26 10:05

user1835316


1 Answers

Your code will work. For simple forms, just add

<asp:HiddenField ClientIDMode="static" ID="hxValue" runat="server"/>

OR

you need to find the client id using

'<%=hxValue.ClientID%>'
like image 137
Akhil Sekharan Avatar answered May 10 '26 00:05

Akhil Sekharan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!