Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By gguerrero
#814876
Hi to everyone,

I have two datepickers (beginning date and end date) on a dynaform and the idea is that in the moment where the user pick a beginning date, the end date automatically sets one day after that (it doesn't matter if is a weekend). I tried with this code but i can't make it work.


Code: Select all
function setEndDate(startDate, days) {  
  var end = moment(startDate); 
  end = add(days, 'days');
  $("#date_end").setValue(end);
}

setEndDate($(#date_begin").getValue(), 1);

$("#date_begin").setOnchange(setEndDate);

Thanks you.
User avatar
By amosbatto
#814878
Do it this way:
Code: Select all
function setEndDate(startDate, nDays) {  
  var end = moment(startDate).add(nDays, 'day');
  $("#date_end").setValue(end);
}

setEndDate($(#date_begin").getValue(), 1);

$("#date_begin").setOnchange( function(newDate, oldDate) {
    setEndDate(newDate, 1);
});
By gguerrero
#814919
Hi amosbatto,

i tried the code that you post and it showed me this error
Code: Select all
Uncaught TypeError: value.replace is not a function
    at setValue (PMDynaform.js:13777)
    at m.fn.init.setValue (PMDynaform.js:377)
    at setFechaTermino (eval at <anonymous> (jquery-1.11.js:2), <anonymous>:85:33)
    at eval (eval at <anonymous> (jquery-1.11.js:2), <anonymous>:88:1)
    at eval (<anonymous>)
    at jquery-1.11.js:2
    at Function.globalEval (jquery-1.11.js:2)
    at m.fn.init.domManip (jquery-1.11.js:3)
    at m.fn.init.append (jquery-1.11.js:3)
    at Script.render (PMDynaform.js:4248)
I tried to add the date format like this "moment(startDate,"YYYY-MM-DD").add....." because i read that it could be the problem, but it didn't work either.

Thank you
User avatar
By amosbatto
#814923
Oh, I see the problem. You need to specify the full format.
Do it this way:
Code: Select all
function setEndDate(startDate, nDays) {  
  var end = '';
  if (startDate != '') {
    end = moment(startDate, "YYYY-MM-DD HH:mm:ss").add(nDays, 'day').format("YYYY-MM-DD HH:mm:ss");
  }  
  $("#date_end").setValue(end);
}

setEndDate($("#date_begin").getValue(), 1);

$("#date_begin").setOnchange( function(newDate, oldDate) {
    setEndDate(newDate, 1);
});
Form to test it:
(3.48 KiB) Downloaded 251 times

Hello. For rental housing, there are software solu[…]

Experience heightened pleasure with Cenforce 100 M[…]

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]