Skip to content

Instantly share code, notes, and snippets.

@RonFields72
Created December 12, 2013 22:33
Show Gist options
  • Save RonFields72/7936771 to your computer and use it in GitHub Desktop.
Save RonFields72/7936771 to your computer and use it in GitHub Desktop.
Get value of ASP.NET hidden field using jQuery.
function DateSelected(sender, eventArgs) {
// get selected date (this is a Telerik RadDatePicker object)
var selectedDate = eventArgs.get_newDate();
// get value of the years until expiration of a valuation (asp hidden field control)
var expirationYears = $('#<%=hfExpirationYears.ClientID%>').val();
//derive months from years
var months = expirationYears * 12;
// calculate a date that is x months from the selected date
var expirationDate = new Date(new Date(selectedDate).setMonth(selectedDate.getMonth() + months));
//format the date display
var labelDisplay = expirationDate.toString("M/d/yyyy");
// update the expiration date on the page (updates an ASP.NET label control)
$("#<%=lblExpirationDate.ClientID%>").html(labelDisplay);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment