Get Value of Hidden Field in Client Side
Asked Answered
S

6

22

On a button click on my server side, I assign value to the Hidden Field from a column in my table.

Dim dsGetEnquiryDetails = dbl.usp_GetEnquiryRegisterDetails(Val(lblEnquiryRegisterID.Text)).AsQueryable
For Each record In dsGetEnquiryDetails
    HiddenStatusFlag.Value = record.StatusFlag
Next

In my client side function I use this, but not getting any value.

var StatusFlag = '';
StatusFlag = document.getElementById('<%= HiddenStatusFlag.ClientID%>');

What am I missing?

Stagehand answered 23/10, 2013 at 7:3 Comment(2)
Often after a "get" like that I'll add a simple alert(StatusFlag); to see what the value is. If it's "null" I know I muffed the command. If it displays something like "[object HtmlInputElement]" I know I got the control instead of the property I intended.Ileum
The Visible property must not be set to false. Otherwise js can't see it. It will still be hidden.Phelgon
F
42

That returns the input. You need the value of the hidden input.

StatusFlag = document.getElementById('<%= HiddenStatusFlag.ClientID%>').value;
Featherveined answered 23/10, 2013 at 7:6 Comment(0)
N
7

If your hiddenfield used runat="server"

Use this code:

StatusFlag = document.getElementById('<%= HiddenStatusFlag.ClientID%>').value; 

else use this code:

StatusFlag = document.getElementById("HiddenStatusFlag").value;
Nomination answered 23/10, 2013 at 7:15 Comment(3)
Hi Ramesh, thanks :) I have fixed this issue using @NunesPascal's suggestion.Stagehand
@Aishvarya Okay fine . Yaar answer'a irunthaa enna ,work mudinja serithaan !!! do well mam !CheersNomination
Mikka Nandri @Ramesh ji :)Stagehand
D
6

Assuming that it's not null you don't use the hiddenfield's value proprty:

var statusFlag = '';
var hiddenStatusFlag = document.getElementById('<%= HiddenStatusFlag.ClientID%>');
if(hiddenStatusFlag != null)
{
    statusFlag = hiddenStatusFlag.value;
}
Deaminate answered 23/10, 2013 at 7:7 Comment(0)
C
5

in jquery:

var hiddenValue = $('#hiddenFieldID').val();
Cassy answered 24/6, 2015 at 15:41 Comment(0)
C
2
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
 <script type="text/javascript" language="javascript">
alert(document.getElementById("<%= Hiddenfield1.ClientID %>").value);
</script>
</head>
<body>

<div>
<asp:hiddenfield ID="Hiddenfield1" runat="server" value="Hussain Testing"></asp:hiddenfield>
</div>
<body>

</html>
Colemancolemanite answered 23/10, 2013 at 7:15 Comment(0)
W
0

in javascript:

var SomeVar = document.getElementById('HiddenField_ID').value;
StatusFlag = SomeVar;
Wasting answered 23/10, 2013 at 10:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.