JavaScript Concatenation

  • 6 October 2016
  • 7 replies
  • 0 views

Userlevel 4
Badge +10

Hi Folks,

I am tinkering around in our new Nintex Forms subscription and I was trying to concatenate some date parts to generate a date format. All of my function works except for one line (the 7th line with concat method). I am not a JS expert but this seems like the correct syntax. Can anyone tell me where I went wrong?

Also, is there a better way to represent code blocks in forum posts?

function loadStrDate(){
    var curDate = new Date();
    var curMonth = curDate.getMonth();
    var curDte = curDate.getDate();
    var curMSYear = curDate.getYear();
    var curYear = curMSYear + 1900;
    var strDate = curMonth.cancat("/",curDte,"/",curYear);
    NWF$('#'+ jsvar_strDate).val(strDate);
};

Thanks and regards,

Patrick Kelligan


7 replies

Userlevel 5
Badge +14

try this

function loadStrDate(){
    var curDate = new Date();
    var curMonth = curDate.getMonth();
    var curDte = curDate.getDate();
    //var curMSYear = curDate.getYear();
    //var curYear = curMSYear + 1900;
    var curYear = curDate.getFullYear();
    var strDate = String(curMonth).concat("/",curDte,"/",curYear);
    NWF$('#'+ jsvar_strDate).val(strDate);
};
Userlevel 4
Badge +10

That  did it! Thanks Marian!

How did you get the code block formatted like it is?

Userlevel 5
Badge +14

happy.png

Userlevel 4
Badge +10

Thanks Marian!

Userlevel 7
Badge +17
function loadStrDate(){
    var curDate = new Date();
    NWF$('#'+ jsvar_strDate).val((curDate.getMonth() + 1) + '/' + curDate.getDate() + '/' + curDate.getFullYear());
};‍‍‍‍‍‍‍‍
Userlevel 7
Badge +17

make sure you do the getMonth + 1 because its return value is from 0 to 11

Userlevel 4
Badge +10

Hi Andrew,

I incorporated your changes and it is much cleaner. Thanks for "+ 1" tip on the month!

Thanks and Regards,

Patrick

Reply