Popup on datepicker











up vote
0
down vote

favorite












I have 3 dates: Present, Start and End.



Present = today's date


Start = any date but i am using past date for my question here



End date = (Present or Start) + number of payments.



If start date is null, end date is calculated based on Present date else it's calculated based on start date.



I have the following logic for remaining payment






function PopulateEndDate() {
var d2;
var paymentDays;
var stDate;
var pDate;

if (document.getElementById("startDate"))
stDate = document.getElementById("startDate").value;
if (document.getElementById("presentDate"))
pDate = document.getElementById("presentDate").value;


var futureSDate = (pDate < stDate); //future start date
var pastSDate = (pDate > stDate); //start date was in the past
var sameDates = (pDate == stDate);




if (stDate && futureSDate){
d2 = new Date(stDate);
}
else if (stDate && sameDates){
d2 = new Date(stDate);
}
else if (stDate && pastSDate){
d2 = new Date(stDate);
alert ("enter total number of payments");
}
else{
d2 = new Date(pDate);
}

var dd = d2.getDate()+1000;
var mm = d2.getMonth()+1;
var yyyy = d2.getFullYear();
var today = (mm+'/'+dd+'/'+yyyy);


var paymentDays = document.getElementById("paymentRemaining").value;

if (paymentDays && paymentDays != "")
// d2.setMonth(d2.getMonth() + parseInt(paymentDays));
var n = d2.getDate();
d2.setDate(1);
d2.setMonth(d2.getMonth() + parseInt(paymentDays));
d2.setDate(Math.min(n, getDaysInMonth(d2.getFullYear(), d2.getMonth())));
if (document.getElementById("endDate"))
document.getElementById("endDate").value = getCurrentDay(d2);
}


function isLeapYear(year) {
return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));
}
function getDaysInMonth(year, month) {
return [31, (isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
}

function getCurrentDay(date) {
var dateOfToday;
if(date && date != "")
dateOfToday = new Date(date);
else dateOfToday = new Date();

var dd = ("0" + (dateOfToday.getDate())).slice(-2);
var mm = ("0" + (dateOfToday.getMonth() + 1)).slice(-2);
var yyyy = dateOfToday.getFullYear();

dateOfToday = yyyy + '-' + mm + '-' + dd;
return dateOfToday;
}

<label>Present Value as of date</label> <input id="presentDate" name="presentDate" onchange="PopulateEndDate()" type="date"><br/><br/>
<label>Start of Lease </label> <input id="startDate" onchange="PopulateEndDate()" type="date" >
<br/>
<br/>
<label>Remaining Payments</label> <input id="paymentRemaining" name = "paymentRemaining" onchange="PopulateEndDate()" type="number" class="label1" style="text-align: right; width:80px;"> <br/><br/>
<label>End of Lease</label> <input id="endDate" onchange="PopulateRentPaymentDates()" type="date" > <br/><br/>





Instead of an alert i want to add a popup only if user picks a date in the past. Is there a way to do that onclick of past date? I think the logic is something as follows. Any help is appreciated. Thank you!



       function myPopUp() {
var startDate = document.getElementById("startDate");
var present = document.getElementById("presentDate");
var pastLease = present > startDate;
if(startDate && pastLease){
//message goes here....
}
}









share|improve this question






















  • What's your intention with the popup? If it's to warn the user that the date is in the past, you could just disable past dates.
    – devlin carnate
    Nov 21 at 18:51










  • You could disable past dates by simply adding 'min' attribute to the input tag and specifying the date. Something like <input id="paymentRemaining" name = "paymentRemaining" min="2018-11-21" onchange="PopulateEndDate()" type="number" class="label1" style="text-align: right; width:80px;">
    – BambiOurLord
    Nov 21 at 18:54










  • @devlincarnate I need the past date so i can't disable it but the popup basically lets the user know that they need to enter total number of payments.
    – ace23
    Nov 21 at 18:54












  • @BambiOurLord I need the past dates.
    – ace23
    Nov 21 at 18:55















up vote
0
down vote

favorite












I have 3 dates: Present, Start and End.



Present = today's date


Start = any date but i am using past date for my question here



End date = (Present or Start) + number of payments.



If start date is null, end date is calculated based on Present date else it's calculated based on start date.



I have the following logic for remaining payment






function PopulateEndDate() {
var d2;
var paymentDays;
var stDate;
var pDate;

if (document.getElementById("startDate"))
stDate = document.getElementById("startDate").value;
if (document.getElementById("presentDate"))
pDate = document.getElementById("presentDate").value;


var futureSDate = (pDate < stDate); //future start date
var pastSDate = (pDate > stDate); //start date was in the past
var sameDates = (pDate == stDate);




if (stDate && futureSDate){
d2 = new Date(stDate);
}
else if (stDate && sameDates){
d2 = new Date(stDate);
}
else if (stDate && pastSDate){
d2 = new Date(stDate);
alert ("enter total number of payments");
}
else{
d2 = new Date(pDate);
}

var dd = d2.getDate()+1000;
var mm = d2.getMonth()+1;
var yyyy = d2.getFullYear();
var today = (mm+'/'+dd+'/'+yyyy);


var paymentDays = document.getElementById("paymentRemaining").value;

if (paymentDays && paymentDays != "")
// d2.setMonth(d2.getMonth() + parseInt(paymentDays));
var n = d2.getDate();
d2.setDate(1);
d2.setMonth(d2.getMonth() + parseInt(paymentDays));
d2.setDate(Math.min(n, getDaysInMonth(d2.getFullYear(), d2.getMonth())));
if (document.getElementById("endDate"))
document.getElementById("endDate").value = getCurrentDay(d2);
}


function isLeapYear(year) {
return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));
}
function getDaysInMonth(year, month) {
return [31, (isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
}

function getCurrentDay(date) {
var dateOfToday;
if(date && date != "")
dateOfToday = new Date(date);
else dateOfToday = new Date();

var dd = ("0" + (dateOfToday.getDate())).slice(-2);
var mm = ("0" + (dateOfToday.getMonth() + 1)).slice(-2);
var yyyy = dateOfToday.getFullYear();

dateOfToday = yyyy + '-' + mm + '-' + dd;
return dateOfToday;
}

<label>Present Value as of date</label> <input id="presentDate" name="presentDate" onchange="PopulateEndDate()" type="date"><br/><br/>
<label>Start of Lease </label> <input id="startDate" onchange="PopulateEndDate()" type="date" >
<br/>
<br/>
<label>Remaining Payments</label> <input id="paymentRemaining" name = "paymentRemaining" onchange="PopulateEndDate()" type="number" class="label1" style="text-align: right; width:80px;"> <br/><br/>
<label>End of Lease</label> <input id="endDate" onchange="PopulateRentPaymentDates()" type="date" > <br/><br/>





Instead of an alert i want to add a popup only if user picks a date in the past. Is there a way to do that onclick of past date? I think the logic is something as follows. Any help is appreciated. Thank you!



       function myPopUp() {
var startDate = document.getElementById("startDate");
var present = document.getElementById("presentDate");
var pastLease = present > startDate;
if(startDate && pastLease){
//message goes here....
}
}









share|improve this question






















  • What's your intention with the popup? If it's to warn the user that the date is in the past, you could just disable past dates.
    – devlin carnate
    Nov 21 at 18:51










  • You could disable past dates by simply adding 'min' attribute to the input tag and specifying the date. Something like <input id="paymentRemaining" name = "paymentRemaining" min="2018-11-21" onchange="PopulateEndDate()" type="number" class="label1" style="text-align: right; width:80px;">
    – BambiOurLord
    Nov 21 at 18:54










  • @devlincarnate I need the past date so i can't disable it but the popup basically lets the user know that they need to enter total number of payments.
    – ace23
    Nov 21 at 18:54












  • @BambiOurLord I need the past dates.
    – ace23
    Nov 21 at 18:55













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have 3 dates: Present, Start and End.



Present = today's date


Start = any date but i am using past date for my question here



End date = (Present or Start) + number of payments.



If start date is null, end date is calculated based on Present date else it's calculated based on start date.



I have the following logic for remaining payment






function PopulateEndDate() {
var d2;
var paymentDays;
var stDate;
var pDate;

if (document.getElementById("startDate"))
stDate = document.getElementById("startDate").value;
if (document.getElementById("presentDate"))
pDate = document.getElementById("presentDate").value;


var futureSDate = (pDate < stDate); //future start date
var pastSDate = (pDate > stDate); //start date was in the past
var sameDates = (pDate == stDate);




if (stDate && futureSDate){
d2 = new Date(stDate);
}
else if (stDate && sameDates){
d2 = new Date(stDate);
}
else if (stDate && pastSDate){
d2 = new Date(stDate);
alert ("enter total number of payments");
}
else{
d2 = new Date(pDate);
}

var dd = d2.getDate()+1000;
var mm = d2.getMonth()+1;
var yyyy = d2.getFullYear();
var today = (mm+'/'+dd+'/'+yyyy);


var paymentDays = document.getElementById("paymentRemaining").value;

if (paymentDays && paymentDays != "")
// d2.setMonth(d2.getMonth() + parseInt(paymentDays));
var n = d2.getDate();
d2.setDate(1);
d2.setMonth(d2.getMonth() + parseInt(paymentDays));
d2.setDate(Math.min(n, getDaysInMonth(d2.getFullYear(), d2.getMonth())));
if (document.getElementById("endDate"))
document.getElementById("endDate").value = getCurrentDay(d2);
}


function isLeapYear(year) {
return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));
}
function getDaysInMonth(year, month) {
return [31, (isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
}

function getCurrentDay(date) {
var dateOfToday;
if(date && date != "")
dateOfToday = new Date(date);
else dateOfToday = new Date();

var dd = ("0" + (dateOfToday.getDate())).slice(-2);
var mm = ("0" + (dateOfToday.getMonth() + 1)).slice(-2);
var yyyy = dateOfToday.getFullYear();

dateOfToday = yyyy + '-' + mm + '-' + dd;
return dateOfToday;
}

<label>Present Value as of date</label> <input id="presentDate" name="presentDate" onchange="PopulateEndDate()" type="date"><br/><br/>
<label>Start of Lease </label> <input id="startDate" onchange="PopulateEndDate()" type="date" >
<br/>
<br/>
<label>Remaining Payments</label> <input id="paymentRemaining" name = "paymentRemaining" onchange="PopulateEndDate()" type="number" class="label1" style="text-align: right; width:80px;"> <br/><br/>
<label>End of Lease</label> <input id="endDate" onchange="PopulateRentPaymentDates()" type="date" > <br/><br/>





Instead of an alert i want to add a popup only if user picks a date in the past. Is there a way to do that onclick of past date? I think the logic is something as follows. Any help is appreciated. Thank you!



       function myPopUp() {
var startDate = document.getElementById("startDate");
var present = document.getElementById("presentDate");
var pastLease = present > startDate;
if(startDate && pastLease){
//message goes here....
}
}









share|improve this question













I have 3 dates: Present, Start and End.



Present = today's date


Start = any date but i am using past date for my question here



End date = (Present or Start) + number of payments.



If start date is null, end date is calculated based on Present date else it's calculated based on start date.



I have the following logic for remaining payment






function PopulateEndDate() {
var d2;
var paymentDays;
var stDate;
var pDate;

if (document.getElementById("startDate"))
stDate = document.getElementById("startDate").value;
if (document.getElementById("presentDate"))
pDate = document.getElementById("presentDate").value;


var futureSDate = (pDate < stDate); //future start date
var pastSDate = (pDate > stDate); //start date was in the past
var sameDates = (pDate == stDate);




if (stDate && futureSDate){
d2 = new Date(stDate);
}
else if (stDate && sameDates){
d2 = new Date(stDate);
}
else if (stDate && pastSDate){
d2 = new Date(stDate);
alert ("enter total number of payments");
}
else{
d2 = new Date(pDate);
}

var dd = d2.getDate()+1000;
var mm = d2.getMonth()+1;
var yyyy = d2.getFullYear();
var today = (mm+'/'+dd+'/'+yyyy);


var paymentDays = document.getElementById("paymentRemaining").value;

if (paymentDays && paymentDays != "")
// d2.setMonth(d2.getMonth() + parseInt(paymentDays));
var n = d2.getDate();
d2.setDate(1);
d2.setMonth(d2.getMonth() + parseInt(paymentDays));
d2.setDate(Math.min(n, getDaysInMonth(d2.getFullYear(), d2.getMonth())));
if (document.getElementById("endDate"))
document.getElementById("endDate").value = getCurrentDay(d2);
}


function isLeapYear(year) {
return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));
}
function getDaysInMonth(year, month) {
return [31, (isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
}

function getCurrentDay(date) {
var dateOfToday;
if(date && date != "")
dateOfToday = new Date(date);
else dateOfToday = new Date();

var dd = ("0" + (dateOfToday.getDate())).slice(-2);
var mm = ("0" + (dateOfToday.getMonth() + 1)).slice(-2);
var yyyy = dateOfToday.getFullYear();

dateOfToday = yyyy + '-' + mm + '-' + dd;
return dateOfToday;
}

<label>Present Value as of date</label> <input id="presentDate" name="presentDate" onchange="PopulateEndDate()" type="date"><br/><br/>
<label>Start of Lease </label> <input id="startDate" onchange="PopulateEndDate()" type="date" >
<br/>
<br/>
<label>Remaining Payments</label> <input id="paymentRemaining" name = "paymentRemaining" onchange="PopulateEndDate()" type="number" class="label1" style="text-align: right; width:80px;"> <br/><br/>
<label>End of Lease</label> <input id="endDate" onchange="PopulateRentPaymentDates()" type="date" > <br/><br/>





Instead of an alert i want to add a popup only if user picks a date in the past. Is there a way to do that onclick of past date? I think the logic is something as follows. Any help is appreciated. Thank you!



       function myPopUp() {
var startDate = document.getElementById("startDate");
var present = document.getElementById("presentDate");
var pastLease = present > startDate;
if(startDate && pastLease){
//message goes here....
}
}





function PopulateEndDate() {
var d2;
var paymentDays;
var stDate;
var pDate;

if (document.getElementById("startDate"))
stDate = document.getElementById("startDate").value;
if (document.getElementById("presentDate"))
pDate = document.getElementById("presentDate").value;


var futureSDate = (pDate < stDate); //future start date
var pastSDate = (pDate > stDate); //start date was in the past
var sameDates = (pDate == stDate);




if (stDate && futureSDate){
d2 = new Date(stDate);
}
else if (stDate && sameDates){
d2 = new Date(stDate);
}
else if (stDate && pastSDate){
d2 = new Date(stDate);
alert ("enter total number of payments");
}
else{
d2 = new Date(pDate);
}

var dd = d2.getDate()+1000;
var mm = d2.getMonth()+1;
var yyyy = d2.getFullYear();
var today = (mm+'/'+dd+'/'+yyyy);


var paymentDays = document.getElementById("paymentRemaining").value;

if (paymentDays && paymentDays != "")
// d2.setMonth(d2.getMonth() + parseInt(paymentDays));
var n = d2.getDate();
d2.setDate(1);
d2.setMonth(d2.getMonth() + parseInt(paymentDays));
d2.setDate(Math.min(n, getDaysInMonth(d2.getFullYear(), d2.getMonth())));
if (document.getElementById("endDate"))
document.getElementById("endDate").value = getCurrentDay(d2);
}


function isLeapYear(year) {
return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));
}
function getDaysInMonth(year, month) {
return [31, (isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
}

function getCurrentDay(date) {
var dateOfToday;
if(date && date != "")
dateOfToday = new Date(date);
else dateOfToday = new Date();

var dd = ("0" + (dateOfToday.getDate())).slice(-2);
var mm = ("0" + (dateOfToday.getMonth() + 1)).slice(-2);
var yyyy = dateOfToday.getFullYear();

dateOfToday = yyyy + '-' + mm + '-' + dd;
return dateOfToday;
}

<label>Present Value as of date</label> <input id="presentDate" name="presentDate" onchange="PopulateEndDate()" type="date"><br/><br/>
<label>Start of Lease </label> <input id="startDate" onchange="PopulateEndDate()" type="date" >
<br/>
<br/>
<label>Remaining Payments</label> <input id="paymentRemaining" name = "paymentRemaining" onchange="PopulateEndDate()" type="number" class="label1" style="text-align: right; width:80px;"> <br/><br/>
<label>End of Lease</label> <input id="endDate" onchange="PopulateRentPaymentDates()" type="date" > <br/><br/>





function PopulateEndDate() {
var d2;
var paymentDays;
var stDate;
var pDate;

if (document.getElementById("startDate"))
stDate = document.getElementById("startDate").value;
if (document.getElementById("presentDate"))
pDate = document.getElementById("presentDate").value;


var futureSDate = (pDate < stDate); //future start date
var pastSDate = (pDate > stDate); //start date was in the past
var sameDates = (pDate == stDate);




if (stDate && futureSDate){
d2 = new Date(stDate);
}
else if (stDate && sameDates){
d2 = new Date(stDate);
}
else if (stDate && pastSDate){
d2 = new Date(stDate);
alert ("enter total number of payments");
}
else{
d2 = new Date(pDate);
}

var dd = d2.getDate()+1000;
var mm = d2.getMonth()+1;
var yyyy = d2.getFullYear();
var today = (mm+'/'+dd+'/'+yyyy);


var paymentDays = document.getElementById("paymentRemaining").value;

if (paymentDays && paymentDays != "")
// d2.setMonth(d2.getMonth() + parseInt(paymentDays));
var n = d2.getDate();
d2.setDate(1);
d2.setMonth(d2.getMonth() + parseInt(paymentDays));
d2.setDate(Math.min(n, getDaysInMonth(d2.getFullYear(), d2.getMonth())));
if (document.getElementById("endDate"))
document.getElementById("endDate").value = getCurrentDay(d2);
}


function isLeapYear(year) {
return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));
}
function getDaysInMonth(year, month) {
return [31, (isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
}

function getCurrentDay(date) {
var dateOfToday;
if(date && date != "")
dateOfToday = new Date(date);
else dateOfToday = new Date();

var dd = ("0" + (dateOfToday.getDate())).slice(-2);
var mm = ("0" + (dateOfToday.getMonth() + 1)).slice(-2);
var yyyy = dateOfToday.getFullYear();

dateOfToday = yyyy + '-' + mm + '-' + dd;
return dateOfToday;
}

<label>Present Value as of date</label> <input id="presentDate" name="presentDate" onchange="PopulateEndDate()" type="date"><br/><br/>
<label>Start of Lease </label> <input id="startDate" onchange="PopulateEndDate()" type="date" >
<br/>
<br/>
<label>Remaining Payments</label> <input id="paymentRemaining" name = "paymentRemaining" onchange="PopulateEndDate()" type="number" class="label1" style="text-align: right; width:80px;"> <br/><br/>
<label>End of Lease</label> <input id="endDate" onchange="PopulateRentPaymentDates()" type="date" > <br/><br/>






javascript






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 at 18:48









ace23

4311




4311












  • What's your intention with the popup? If it's to warn the user that the date is in the past, you could just disable past dates.
    – devlin carnate
    Nov 21 at 18:51










  • You could disable past dates by simply adding 'min' attribute to the input tag and specifying the date. Something like <input id="paymentRemaining" name = "paymentRemaining" min="2018-11-21" onchange="PopulateEndDate()" type="number" class="label1" style="text-align: right; width:80px;">
    – BambiOurLord
    Nov 21 at 18:54










  • @devlincarnate I need the past date so i can't disable it but the popup basically lets the user know that they need to enter total number of payments.
    – ace23
    Nov 21 at 18:54












  • @BambiOurLord I need the past dates.
    – ace23
    Nov 21 at 18:55


















  • What's your intention with the popup? If it's to warn the user that the date is in the past, you could just disable past dates.
    – devlin carnate
    Nov 21 at 18:51










  • You could disable past dates by simply adding 'min' attribute to the input tag and specifying the date. Something like <input id="paymentRemaining" name = "paymentRemaining" min="2018-11-21" onchange="PopulateEndDate()" type="number" class="label1" style="text-align: right; width:80px;">
    – BambiOurLord
    Nov 21 at 18:54










  • @devlincarnate I need the past date so i can't disable it but the popup basically lets the user know that they need to enter total number of payments.
    – ace23
    Nov 21 at 18:54












  • @BambiOurLord I need the past dates.
    – ace23
    Nov 21 at 18:55
















What's your intention with the popup? If it's to warn the user that the date is in the past, you could just disable past dates.
– devlin carnate
Nov 21 at 18:51




What's your intention with the popup? If it's to warn the user that the date is in the past, you could just disable past dates.
– devlin carnate
Nov 21 at 18:51












You could disable past dates by simply adding 'min' attribute to the input tag and specifying the date. Something like <input id="paymentRemaining" name = "paymentRemaining" min="2018-11-21" onchange="PopulateEndDate()" type="number" class="label1" style="text-align: right; width:80px;">
– BambiOurLord
Nov 21 at 18:54




You could disable past dates by simply adding 'min' attribute to the input tag and specifying the date. Something like <input id="paymentRemaining" name = "paymentRemaining" min="2018-11-21" onchange="PopulateEndDate()" type="number" class="label1" style="text-align: right; width:80px;">
– BambiOurLord
Nov 21 at 18:54












@devlincarnate I need the past date so i can't disable it but the popup basically lets the user know that they need to enter total number of payments.
– ace23
Nov 21 at 18:54






@devlincarnate I need the past date so i can't disable it but the popup basically lets the user know that they need to enter total number of payments.
– ace23
Nov 21 at 18:54














@BambiOurLord I need the past dates.
– ace23
Nov 21 at 18:55




@BambiOurLord I need the past dates.
– ace23
Nov 21 at 18:55












1 Answer
1






active

oldest

votes

















up vote
-1
down vote













There are multiple ways of doing it and it also depends on where and how you want to display the popup. Here's a simple example of how you could add a pop up on a click of a button.






let btn = document.getElementById("test");

btn.addEventListener( "click", function(){
if ( document.getElementById("popup") ) {
document.getElementById("popup").style.display = "block";
}
});

#popup {
display: none;
width: 300px;
height: 50px;;
margin: 0 auto;
background-color: lightblue;
border-radius: 15px;
text-align: center;
}

#popupMessage {
font-size: 30px;
}

<div id="popup">
<p id="popupMessage"> Your Popup Message</p>
</div>

<button id="test"> Popup</button>





In your case you could add the myPopUp()function to date field which you want to be triggering the function. Then once the condition is met you could dynamically create DOM elements which will act as your pop up which can then also be appended to any other element in your markup code. Here is a simple example of what I described above.






let condition = false;

let btn = document.getElementById("popupBtn");

btn.addEventListener("click", function(){
//set some condition to true on button click
condition = true;

//if condition is true then add the popup
if ( condition ) {
//create container
let popupContainer = document.createElement("DIV");
//add popupContainer class to the container
popupContainer.setAttribute("class", "popupContainer");

//create popup text
let popupText = document.createElement("P");
popupText.setAttribute("class", "popupMessage");
//add popup text
popupText.appendChild( document.createTextNode("Your Popup Message") );

//add the popupText to popupContainer
popupContainer.appendChild( popupText );


//add the popup above p element with id popupAboveThisElement
if ( document.getElementById("popupAboveThisElement") ) {
document.getElementById("popupAboveThisElement").parentNode.insertBefore( popupContainer, document.getElementById("popupAboveThisElement") );
}
}//end if condition true
});

.popupContainer {
display: block;
width: 300px;
height: 50px;;
margin: 0 auto;
background-color: lightblue;
border-radius: 15px;
text-align: center;
}

.popupMessage {
font-size: 30px;
}

<h1> A title </h1>

<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ea, mollitia dolorem repellat tenetur, et eligendi, ipsam consequuntur debitis temporibus laboriosam ducimus harum fuga, quae ipsa.</p>

<p id="popupAboveThisElement"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Excepturi, quis, nihil modi fuga debitis error delectus itaque est illum velit in aliquam deserunt ipsum, non cupiditate, alias consectetur. Saepe, deleniti, aliquid. Fugiat sit, iste, tempore optio nam dolorum alias maxime quam numquam autem aspernatur porro beatae. Fugiat saepe doloremque facere!</p>

<button id="popupBtn"> Display Popup</button>





I hope this is of help to you.






share|improve this answer























  • If someone down-votes, could you please at least leave a comment as to why it was down-voted so that I may improve the answer ?
    – BambiOurLord
    Nov 21 at 19:43











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418730%2fpopup-on-datepicker%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
-1
down vote













There are multiple ways of doing it and it also depends on where and how you want to display the popup. Here's a simple example of how you could add a pop up on a click of a button.






let btn = document.getElementById("test");

btn.addEventListener( "click", function(){
if ( document.getElementById("popup") ) {
document.getElementById("popup").style.display = "block";
}
});

#popup {
display: none;
width: 300px;
height: 50px;;
margin: 0 auto;
background-color: lightblue;
border-radius: 15px;
text-align: center;
}

#popupMessage {
font-size: 30px;
}

<div id="popup">
<p id="popupMessage"> Your Popup Message</p>
</div>

<button id="test"> Popup</button>





In your case you could add the myPopUp()function to date field which you want to be triggering the function. Then once the condition is met you could dynamically create DOM elements which will act as your pop up which can then also be appended to any other element in your markup code. Here is a simple example of what I described above.






let condition = false;

let btn = document.getElementById("popupBtn");

btn.addEventListener("click", function(){
//set some condition to true on button click
condition = true;

//if condition is true then add the popup
if ( condition ) {
//create container
let popupContainer = document.createElement("DIV");
//add popupContainer class to the container
popupContainer.setAttribute("class", "popupContainer");

//create popup text
let popupText = document.createElement("P");
popupText.setAttribute("class", "popupMessage");
//add popup text
popupText.appendChild( document.createTextNode("Your Popup Message") );

//add the popupText to popupContainer
popupContainer.appendChild( popupText );


//add the popup above p element with id popupAboveThisElement
if ( document.getElementById("popupAboveThisElement") ) {
document.getElementById("popupAboveThisElement").parentNode.insertBefore( popupContainer, document.getElementById("popupAboveThisElement") );
}
}//end if condition true
});

.popupContainer {
display: block;
width: 300px;
height: 50px;;
margin: 0 auto;
background-color: lightblue;
border-radius: 15px;
text-align: center;
}

.popupMessage {
font-size: 30px;
}

<h1> A title </h1>

<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ea, mollitia dolorem repellat tenetur, et eligendi, ipsam consequuntur debitis temporibus laboriosam ducimus harum fuga, quae ipsa.</p>

<p id="popupAboveThisElement"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Excepturi, quis, nihil modi fuga debitis error delectus itaque est illum velit in aliquam deserunt ipsum, non cupiditate, alias consectetur. Saepe, deleniti, aliquid. Fugiat sit, iste, tempore optio nam dolorum alias maxime quam numquam autem aspernatur porro beatae. Fugiat saepe doloremque facere!</p>

<button id="popupBtn"> Display Popup</button>





I hope this is of help to you.






share|improve this answer























  • If someone down-votes, could you please at least leave a comment as to why it was down-voted so that I may improve the answer ?
    – BambiOurLord
    Nov 21 at 19:43















up vote
-1
down vote













There are multiple ways of doing it and it also depends on where and how you want to display the popup. Here's a simple example of how you could add a pop up on a click of a button.






let btn = document.getElementById("test");

btn.addEventListener( "click", function(){
if ( document.getElementById("popup") ) {
document.getElementById("popup").style.display = "block";
}
});

#popup {
display: none;
width: 300px;
height: 50px;;
margin: 0 auto;
background-color: lightblue;
border-radius: 15px;
text-align: center;
}

#popupMessage {
font-size: 30px;
}

<div id="popup">
<p id="popupMessage"> Your Popup Message</p>
</div>

<button id="test"> Popup</button>





In your case you could add the myPopUp()function to date field which you want to be triggering the function. Then once the condition is met you could dynamically create DOM elements which will act as your pop up which can then also be appended to any other element in your markup code. Here is a simple example of what I described above.






let condition = false;

let btn = document.getElementById("popupBtn");

btn.addEventListener("click", function(){
//set some condition to true on button click
condition = true;

//if condition is true then add the popup
if ( condition ) {
//create container
let popupContainer = document.createElement("DIV");
//add popupContainer class to the container
popupContainer.setAttribute("class", "popupContainer");

//create popup text
let popupText = document.createElement("P");
popupText.setAttribute("class", "popupMessage");
//add popup text
popupText.appendChild( document.createTextNode("Your Popup Message") );

//add the popupText to popupContainer
popupContainer.appendChild( popupText );


//add the popup above p element with id popupAboveThisElement
if ( document.getElementById("popupAboveThisElement") ) {
document.getElementById("popupAboveThisElement").parentNode.insertBefore( popupContainer, document.getElementById("popupAboveThisElement") );
}
}//end if condition true
});

.popupContainer {
display: block;
width: 300px;
height: 50px;;
margin: 0 auto;
background-color: lightblue;
border-radius: 15px;
text-align: center;
}

.popupMessage {
font-size: 30px;
}

<h1> A title </h1>

<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ea, mollitia dolorem repellat tenetur, et eligendi, ipsam consequuntur debitis temporibus laboriosam ducimus harum fuga, quae ipsa.</p>

<p id="popupAboveThisElement"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Excepturi, quis, nihil modi fuga debitis error delectus itaque est illum velit in aliquam deserunt ipsum, non cupiditate, alias consectetur. Saepe, deleniti, aliquid. Fugiat sit, iste, tempore optio nam dolorum alias maxime quam numquam autem aspernatur porro beatae. Fugiat saepe doloremque facere!</p>

<button id="popupBtn"> Display Popup</button>





I hope this is of help to you.






share|improve this answer























  • If someone down-votes, could you please at least leave a comment as to why it was down-voted so that I may improve the answer ?
    – BambiOurLord
    Nov 21 at 19:43













up vote
-1
down vote










up vote
-1
down vote









There are multiple ways of doing it and it also depends on where and how you want to display the popup. Here's a simple example of how you could add a pop up on a click of a button.






let btn = document.getElementById("test");

btn.addEventListener( "click", function(){
if ( document.getElementById("popup") ) {
document.getElementById("popup").style.display = "block";
}
});

#popup {
display: none;
width: 300px;
height: 50px;;
margin: 0 auto;
background-color: lightblue;
border-radius: 15px;
text-align: center;
}

#popupMessage {
font-size: 30px;
}

<div id="popup">
<p id="popupMessage"> Your Popup Message</p>
</div>

<button id="test"> Popup</button>





In your case you could add the myPopUp()function to date field which you want to be triggering the function. Then once the condition is met you could dynamically create DOM elements which will act as your pop up which can then also be appended to any other element in your markup code. Here is a simple example of what I described above.






let condition = false;

let btn = document.getElementById("popupBtn");

btn.addEventListener("click", function(){
//set some condition to true on button click
condition = true;

//if condition is true then add the popup
if ( condition ) {
//create container
let popupContainer = document.createElement("DIV");
//add popupContainer class to the container
popupContainer.setAttribute("class", "popupContainer");

//create popup text
let popupText = document.createElement("P");
popupText.setAttribute("class", "popupMessage");
//add popup text
popupText.appendChild( document.createTextNode("Your Popup Message") );

//add the popupText to popupContainer
popupContainer.appendChild( popupText );


//add the popup above p element with id popupAboveThisElement
if ( document.getElementById("popupAboveThisElement") ) {
document.getElementById("popupAboveThisElement").parentNode.insertBefore( popupContainer, document.getElementById("popupAboveThisElement") );
}
}//end if condition true
});

.popupContainer {
display: block;
width: 300px;
height: 50px;;
margin: 0 auto;
background-color: lightblue;
border-radius: 15px;
text-align: center;
}

.popupMessage {
font-size: 30px;
}

<h1> A title </h1>

<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ea, mollitia dolorem repellat tenetur, et eligendi, ipsam consequuntur debitis temporibus laboriosam ducimus harum fuga, quae ipsa.</p>

<p id="popupAboveThisElement"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Excepturi, quis, nihil modi fuga debitis error delectus itaque est illum velit in aliquam deserunt ipsum, non cupiditate, alias consectetur. Saepe, deleniti, aliquid. Fugiat sit, iste, tempore optio nam dolorum alias maxime quam numquam autem aspernatur porro beatae. Fugiat saepe doloremque facere!</p>

<button id="popupBtn"> Display Popup</button>





I hope this is of help to you.






share|improve this answer














There are multiple ways of doing it and it also depends on where and how you want to display the popup. Here's a simple example of how you could add a pop up on a click of a button.






let btn = document.getElementById("test");

btn.addEventListener( "click", function(){
if ( document.getElementById("popup") ) {
document.getElementById("popup").style.display = "block";
}
});

#popup {
display: none;
width: 300px;
height: 50px;;
margin: 0 auto;
background-color: lightblue;
border-radius: 15px;
text-align: center;
}

#popupMessage {
font-size: 30px;
}

<div id="popup">
<p id="popupMessage"> Your Popup Message</p>
</div>

<button id="test"> Popup</button>





In your case you could add the myPopUp()function to date field which you want to be triggering the function. Then once the condition is met you could dynamically create DOM elements which will act as your pop up which can then also be appended to any other element in your markup code. Here is a simple example of what I described above.






let condition = false;

let btn = document.getElementById("popupBtn");

btn.addEventListener("click", function(){
//set some condition to true on button click
condition = true;

//if condition is true then add the popup
if ( condition ) {
//create container
let popupContainer = document.createElement("DIV");
//add popupContainer class to the container
popupContainer.setAttribute("class", "popupContainer");

//create popup text
let popupText = document.createElement("P");
popupText.setAttribute("class", "popupMessage");
//add popup text
popupText.appendChild( document.createTextNode("Your Popup Message") );

//add the popupText to popupContainer
popupContainer.appendChild( popupText );


//add the popup above p element with id popupAboveThisElement
if ( document.getElementById("popupAboveThisElement") ) {
document.getElementById("popupAboveThisElement").parentNode.insertBefore( popupContainer, document.getElementById("popupAboveThisElement") );
}
}//end if condition true
});

.popupContainer {
display: block;
width: 300px;
height: 50px;;
margin: 0 auto;
background-color: lightblue;
border-radius: 15px;
text-align: center;
}

.popupMessage {
font-size: 30px;
}

<h1> A title </h1>

<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ea, mollitia dolorem repellat tenetur, et eligendi, ipsam consequuntur debitis temporibus laboriosam ducimus harum fuga, quae ipsa.</p>

<p id="popupAboveThisElement"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Excepturi, quis, nihil modi fuga debitis error delectus itaque est illum velit in aliquam deserunt ipsum, non cupiditate, alias consectetur. Saepe, deleniti, aliquid. Fugiat sit, iste, tempore optio nam dolorum alias maxime quam numquam autem aspernatur porro beatae. Fugiat saepe doloremque facere!</p>

<button id="popupBtn"> Display Popup</button>





I hope this is of help to you.






let btn = document.getElementById("test");

btn.addEventListener( "click", function(){
if ( document.getElementById("popup") ) {
document.getElementById("popup").style.display = "block";
}
});

#popup {
display: none;
width: 300px;
height: 50px;;
margin: 0 auto;
background-color: lightblue;
border-radius: 15px;
text-align: center;
}

#popupMessage {
font-size: 30px;
}

<div id="popup">
<p id="popupMessage"> Your Popup Message</p>
</div>

<button id="test"> Popup</button>





let btn = document.getElementById("test");

btn.addEventListener( "click", function(){
if ( document.getElementById("popup") ) {
document.getElementById("popup").style.display = "block";
}
});

#popup {
display: none;
width: 300px;
height: 50px;;
margin: 0 auto;
background-color: lightblue;
border-radius: 15px;
text-align: center;
}

#popupMessage {
font-size: 30px;
}

<div id="popup">
<p id="popupMessage"> Your Popup Message</p>
</div>

<button id="test"> Popup</button>





let condition = false;

let btn = document.getElementById("popupBtn");

btn.addEventListener("click", function(){
//set some condition to true on button click
condition = true;

//if condition is true then add the popup
if ( condition ) {
//create container
let popupContainer = document.createElement("DIV");
//add popupContainer class to the container
popupContainer.setAttribute("class", "popupContainer");

//create popup text
let popupText = document.createElement("P");
popupText.setAttribute("class", "popupMessage");
//add popup text
popupText.appendChild( document.createTextNode("Your Popup Message") );

//add the popupText to popupContainer
popupContainer.appendChild( popupText );


//add the popup above p element with id popupAboveThisElement
if ( document.getElementById("popupAboveThisElement") ) {
document.getElementById("popupAboveThisElement").parentNode.insertBefore( popupContainer, document.getElementById("popupAboveThisElement") );
}
}//end if condition true
});

.popupContainer {
display: block;
width: 300px;
height: 50px;;
margin: 0 auto;
background-color: lightblue;
border-radius: 15px;
text-align: center;
}

.popupMessage {
font-size: 30px;
}

<h1> A title </h1>

<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ea, mollitia dolorem repellat tenetur, et eligendi, ipsam consequuntur debitis temporibus laboriosam ducimus harum fuga, quae ipsa.</p>

<p id="popupAboveThisElement"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Excepturi, quis, nihil modi fuga debitis error delectus itaque est illum velit in aliquam deserunt ipsum, non cupiditate, alias consectetur. Saepe, deleniti, aliquid. Fugiat sit, iste, tempore optio nam dolorum alias maxime quam numquam autem aspernatur porro beatae. Fugiat saepe doloremque facere!</p>

<button id="popupBtn"> Display Popup</button>





let condition = false;

let btn = document.getElementById("popupBtn");

btn.addEventListener("click", function(){
//set some condition to true on button click
condition = true;

//if condition is true then add the popup
if ( condition ) {
//create container
let popupContainer = document.createElement("DIV");
//add popupContainer class to the container
popupContainer.setAttribute("class", "popupContainer");

//create popup text
let popupText = document.createElement("P");
popupText.setAttribute("class", "popupMessage");
//add popup text
popupText.appendChild( document.createTextNode("Your Popup Message") );

//add the popupText to popupContainer
popupContainer.appendChild( popupText );


//add the popup above p element with id popupAboveThisElement
if ( document.getElementById("popupAboveThisElement") ) {
document.getElementById("popupAboveThisElement").parentNode.insertBefore( popupContainer, document.getElementById("popupAboveThisElement") );
}
}//end if condition true
});

.popupContainer {
display: block;
width: 300px;
height: 50px;;
margin: 0 auto;
background-color: lightblue;
border-radius: 15px;
text-align: center;
}

.popupMessage {
font-size: 30px;
}

<h1> A title </h1>

<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ea, mollitia dolorem repellat tenetur, et eligendi, ipsam consequuntur debitis temporibus laboriosam ducimus harum fuga, quae ipsa.</p>

<p id="popupAboveThisElement"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Excepturi, quis, nihil modi fuga debitis error delectus itaque est illum velit in aliquam deserunt ipsum, non cupiditate, alias consectetur. Saepe, deleniti, aliquid. Fugiat sit, iste, tempore optio nam dolorum alias maxime quam numquam autem aspernatur porro beatae. Fugiat saepe doloremque facere!</p>

<button id="popupBtn"> Display Popup</button>






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 at 19:42

























answered Nov 21 at 19:27









BambiOurLord

1809




1809












  • If someone down-votes, could you please at least leave a comment as to why it was down-voted so that I may improve the answer ?
    – BambiOurLord
    Nov 21 at 19:43


















  • If someone down-votes, could you please at least leave a comment as to why it was down-voted so that I may improve the answer ?
    – BambiOurLord
    Nov 21 at 19:43
















If someone down-votes, could you please at least leave a comment as to why it was down-voted so that I may improve the answer ?
– BambiOurLord
Nov 21 at 19:43




If someone down-votes, could you please at least leave a comment as to why it was down-voted so that I may improve the answer ?
– BambiOurLord
Nov 21 at 19:43


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418730%2fpopup-on-datepicker%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

What visual should I use to simply compare current year value vs last year in Power BI desktop

How to ignore python UserWarning in pytest?

Alexandru Averescu