views:

304

answers:

2

Why cant i get the value ofthis hidden field?

I have a control...

<asp:HiddenField ID="HiddenFieldServerDateTime" runat="server" />

Which rendwrs as...

<input type="hidden" name="ctl00$cph_main$HiddenFieldServerDateTime" id="ctl00_cph_main_HiddenFieldServerDateTime" value="08/01/2010 10:54:11" 

Which im tryoing to get the value of using...

var serverDateTime = $("#HiddenFieldServerDateTime").attr('value');

So whats wrong? Or am i stupid?

+3  A: 
Darin Dimitrov
Thankyou! That makes complete sense
Dooie
A: 

Add a class attribute ".myHiddenValue" to the tag then use

var myVal = $(".myHiddenValue").val()

or since this will render after loading the document my advise use this

$(document).ready(function(){
   var myVal = $("input[name='ctl00$cph_main$HiddenFieldServerDateTime']").val();
 }
);

Note: also applies for the first example as well
joberror
thankyou! Your answer and Darin Dimitrov's really helped
Dooie