0

Total newbie, please don't rush to mark as duplicate!

I have a file that calculates days based on a date picker, adding 1 day to many multiple fields. What I need is to give the option to manually add numbers which are treated as days.

I kinda figured it to an extend, but then it adds the number as a text (if you choose 1st of January and add 3, it gives you the 13th of January). I saw the question of a guy with a similar issue and tried to implement it, but have no idea how. So I have added it here: http://code.reloado.com/avudiz3/edit#preview (edit here: http://code.reloado.com/avudiz3/edit#javascript,html) and will appreciate any help or advise.

  • It seems that you concatenate strings... http://stackoverflow.com/questions/9280057/numerical-value-of-number-input-by-user-in-a-text-field – sinisake Dec 25 '16 at 12:22
  • P.S. Merry Christmas everyone – N Alexander Dec 25 '16 at 12:23
  • @sinisake Totally agree with you - I have been browsing this for a while and also saw this question. I know ppl here are more advanced, but I am not sure how exactly to edit this and can't make sense of it all... – N Alexander Dec 25 '16 at 12:25
  • http://code.reloado.com/avudiz3/4/edit So, you will notice small change in your arrival section. – sinisake Dec 25 '16 at 12:34
  • @sinisake You are my hero! Can you add this as an answer, so I can mark it correct? You're a genius! – N Alexander Dec 25 '16 at 12:37
  • Lol, thanks, np, BUT, this is not complete solution - try to choose one biggest date - e.g. 31. Dec... add 5,6 days - and you will see interesting result... So, whole var should be treated as date, rather... Will post solution soon. – sinisake Dec 25 '16 at 12:38
  • @sinisake I see what you mean and can hardly express my gratitude for your help :) I treat it as the biggest Xmas present :) – N Alexander Dec 25 '16 at 12:42

2 Answers2

0

its because your are adding the date typed in input field to the actual date selected and the Day property of date is string ... So if you add 2 strings like this "1" + "3" = "13" or even if actual date is integer then 1 + "3" = "13" still will be equal to "13" because input text is in string format .. What you can try is convert the number entered in input ...

var numb = parseInt(text entered in input feild)

Hope this helps ...

Daniyal Awan
  • 107
  • 5
0

So, solution is to do this, in your arrival section: (this way you will get real date, not just number).

newdate.setDate(newdate.getDate()+parseInt(goose));

Demo: http://code.reloado.com/avudiz3/14/edit

sinisake
  • 11,240
  • 2
  • 19
  • 27