0

i'm going to create form which allow users selected date as their want, so here is my demo

this is my script $('#datePick').multiDatesPicker();

then this is the demo

my question is how can i count how many date their selected before submit to form, thanks

subodh
  • 6,136
  • 12
  • 51
  • 73
Freddy Sidauruk
  • 300
  • 6
  • 17

2 Answers2

2

The plugin has function for this. Calling the multiDatesPicker('getDate') on your jQuery object wil give you the dates in an array, you can call the Array function length on it to get the count.

var dates = $('#your_selector').multiDatesPicker('getDates').length;

Made a Fiddle for you: http://jsfiddle.net/3t4j9/786/

sidneydobber
  • 2,790
  • 1
  • 23
  • 32
  • thanks sidney, before that i use php languange to count how many date – Freddy Sidauruk Jan 15 '16 at 02:03
  • If the answer was correct could you mark it resolved, by pressing the check button on my answer? :) – sidneydobber Jan 15 '16 at 06:11
  • done, but now i have little problem ? plase see your fiddle, the format is dd/mm/yyyy but in my database format is yyyy/dd/mm how can i make it become easy to edit ? i use this kueri GROUP_CONCAT(cu_date_date SEPARATOR ',') as wholecuti in my view it will not show but after i remove the selector it came up, – Freddy Sidauruk Jan 15 '16 at 07:51
  • I asume that since it is based on jQuery's datepicker the following will work http://stackoverflow.com/questions/1328025/jquery-ui-datepicker-change-date-format – sidneydobber Jan 15 '16 at 08:36
  • hello sidnye let clear first, i have data in db 2016-02-09,2016-02-10,2016-02-15,2016-02-18 but the format in datepicker is mm/dd/yyyy how can i make it work from database, i'm getting progress edit form, thanks – Freddy Sidauruk Jan 15 '16 at 08:37
  • the main goal is i want ato select date which came from database for edit – Freddy Sidauruk Jan 15 '16 at 08:40
  • Thanks for your support, last question if i have data in database like 2016-01-10,2016-01-15 how can i make it selected in datepicker, spend more than 3 hours but not results ! i use input type hidden to get value frpom database, here is my simple fiddle http://jsfiddle.net/dauruk0512/1c43vxt0/1/ – Freddy Sidauruk Jan 15 '16 at 09:48
0

Considering the fact that the datepicker is fundamentally a textbox, you can call the .val() in jQuery to fetch its text value and then split on the delimiter (comma, in your case) and take the length of the resulting array to get the number of dates selected.

That is

var datesCount = $('#datePick').val().split(',').length;
Sarath Chandra
  • 1,850
  • 19
  • 40