1

I have a dropdown with dates on a webshop, pushed from an external service:

<select id="leverdatum" class="" name="attribute_leverdatum" data-attribute_name="attribute_leverdatum" data-show_option_none="yes">
  <option value="">Een optie kiezen</option>
  <option value="ma 23.03.2020" >ma 23.03.2020</option>
  <option value="wo 25.03.2020" >wo 25.03.2020</option>
  <option value="vr 27.03.2020" >vr 27.03.2020</option>
  <option value="ma 30.03.2020" >ma 30.03.2020</option>
</select>

When a customer orders a product, I want to check if the nearest date in the future min. 48h reservation/delivery from the pulldown.

Example:

  • Order product on 23/03/2020, next delivery is on 25/03/2020
  • Order product on 24/03/2020, next delivery is on 27/03/2020

I know this is possible with an Input field and the jQuery DatePicker, but this is not an option, because the pulldown is pushed from an external service, and on this service is not a possibility integrated to do the control/check date.

So I search for an frontend solution with Javascript or jQuery. Can somebody help me with this, or has experience with similar problem?

Romi Halasz
  • 1,949
  • 1
  • 13
  • 23
Tuxy
  • 91
  • 10
  • The answer here uses moment to calculate days difference between two dates - https://stackoverflow.com/questions/9129928/how-to-calculate-number-of-days-between-two-dates - You could loop over your select options until you find one that is acceptable and set it to selected. – dmoo Mar 23 '20 at 14:30
  • yes, i know calculate days, but there are more challenges to do: - how make a loop for adding the values (in an array?) - how filter this dates (ma 23.03.2020, wo 25.03.2020,...) to a date format JS can understand? – Tuxy Mar 23 '20 at 14:38
  • Okay, my first challenge (filter the values from the dropdown) is accomplished with the help from this website: https://usefulangle.com/post/254/javascript-loop-through-select-options Next step is how 'convert' the values to a Date-object and calculate two dates and after that hide the dates are < 2 days. – Tuxy Mar 23 '20 at 15:13

0 Answers0