To implement a backend solution where the date is stored in a hidden field, formatted, and then displayed via alertify, you need to take the following steps:
Server-side (Backend): Set the date value in the hidden field, ensuring it's a proper Date format (e.g., yyyy-MM-dd or a JavaScript-friendly string).
Client-side (JavaScript): Retrieve that value, format it to the desired format, and then show it in an alertify alert.
1. Server-Side: Set the Date in the Hidden Field
For the server-side, let's assume you're using ASP.NET or any server-side language to inject the date into the hidden field. Here’s an example in ASP.NET:
ASP.NET (C#) Example
In your ASP.NET code (C#), you might set the hidden field like this:
<!-- In your ASP.NET markup -->
<input type="hidden" id="issuefromdatehdn" runat="server" value="<%= DateTime.Now.ToString("yyyy-MM-dd") %>" />
(or)
<asp:Hidden id="issuefromdatehdn" runat="server">
Backend Data Bind :
issuefromdatehdn.Value=ds.Tables[0].Rows[0]["Startdate"].ToString();
This sets the value of the hidden field to the current date in the format yyyy-MM-dd (e.g., 2025-11-05).
2. Client-Side JavaScript: Format the Date and Display in Alertify
Next, in your JavaScript, you will read that hidden field's value, format it to DD-MMM-YYYY, and display it in the alertify alert.
Updated JavaScript Example
function Upcomingoffline() {
// Get the date string from the hidden field
var issueDateString = document.getElementById('issuefromdatehdn').value;
// Create a Date object from the string
var date = new Date(issueDateString);
// Array of month names for formatted month
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
// Format the date to "DD-MMM-YYYY"
var formattedDate = ("0" + date.getDate()).slice(-2) + "-" + months[date.getMonth()] + "-" + date.getFullYear();
// Show the alert with the formatted date
alertify.alert("Your Application is processed. You will receive mandate on " + formattedDate + ".", function (e) {
if (e) {
window.history.pushState(null, "", window.location.href);
window.location = '/test.aspx';
} else {
window.location = '/test2.aspx';
}
});
}
Explanation
Retrieve Hidden Field Value
Formatting the Date
The new Date(issueDateString) creates a Date object from the string.
We extract the day, month, and year, then reformat the date as DD-MMM-YYYY (e.g., 05-Nov-2025).
Displaying the Date in Alertify
Putting It All Together
The hidden field issuefromdatehdn is populated on the server-side, where the date is formatted (in yyyy-MM-dd format).
When the JavaScript function Upcomingoffline() runs, it retrieves the value, formats the date, and then shows the formatted date in the alertify message.