Hidden field value in javascript
-
Hi, This has both C# and Javascript. Not sure if it is the correct forum. I have a hidden field value on an apsx page, which is populated on PageLoad. I am trying to request this value in javascript. The value does load from PageLoad, because I can see this value on page view source for the hidden aspx field. But when i try to request this value in javascript, the value is null. I know it is null since I am using alert statements to see this value. Am I missing a syntax? Many thanks!!
<script type="text/javascript">
<!--
var emailAddress = document.getElementById('<%=hfEmail.ClientID%>');
alert('Hi!');
alert('Hi - ' + emailAddress);
alert(emailAddress.value);//-->
</script></pre>
ASPX code
-
Hi, This has both C# and Javascript. Not sure if it is the correct forum. I have a hidden field value on an apsx page, which is populated on PageLoad. I am trying to request this value in javascript. The value does load from PageLoad, because I can see this value on page view source for the hidden aspx field. But when i try to request this value in javascript, the value is null. I know it is null since I am using alert statements to see this value. Am I missing a syntax? Many thanks!!
<script type="text/javascript">
<!--
var emailAddress = document.getElementById('<%=hfEmail.ClientID%>');
alert('Hi!');
alert('Hi - ' + emailAddress);
alert(emailAddress.value);//-->
</script></pre>
ASPX code
check emailAddress emailAddress null pointer ? property .value exists ? range of value of .value ? HTML funktion document.getElementById() uses param during parsing of document so '<%=hfEmail.ClientID%>' must be a real ID or filled BEFORE parsing javascript. put javascript at end of body, no in head (head is parsed at first before body). .... what you want //--> </script></pre> // where is <pre>
-
Hi, This has both C# and Javascript. Not sure if it is the correct forum. I have a hidden field value on an apsx page, which is populated on PageLoad. I am trying to request this value in javascript. The value does load from PageLoad, because I can see this value on page view source for the hidden aspx field. But when i try to request this value in javascript, the value is null. I know it is null since I am using alert statements to see this value. Am I missing a syntax? Many thanks!!
<script type="text/javascript">
<!--
var emailAddress = document.getElementById('<%=hfEmail.ClientID%>');
alert('Hi!');
alert('Hi - ' + emailAddress);
alert(emailAddress.value);//-->
</script></pre>
ASPX code
Can you show the PageLoad function?
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is (V).
-
Can you show the PageLoad function?
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is (V).
-
This is the syntax, to be placed with in the body of email: var createdate = '<%=hdnCreateDate.Value%>';
try it in jquery ready function. $(document).ready(function() { var hiddenVal=$("#YourId").val(); }); if you use master page in aspx, then you can find the element by name also. $("input[name='elementName']")