views:

34

answers:

1

So, the latest dilemma I am facing:

I am using jQuery DatePick (not DatePicker) to select dates and populate an input field with these dates. The problem is that the input field will get filled every time I click a date. Therefore, if I click the 23rd, then click it again to DEselect it, it automatically gets added to the input (and therefore the database array) twice.

Code below:

    <script type="text/javascript">
 $(document).ready(
  function (){
  $('.datePick').datepick({ 
      //rangeSelect: true,
   multiSelect: 999, 
   monthsToShow: 2,
   multiSeparator: ':',
   monthsToShow: 3, 
   monthsToStep: 3, 
      prevText: 'Prev months', 
   nextText: 'Next months',
   onSelect: function(date) 
   { 
    var all_dates = $('#dateSelect').val();
          for (var i = 0; i < date.length; i++) 
    { 
              all_dates = ':'+$.datepick.formatDate('yyyy-mm-dd', date[i]);
          } 
          $('#dateSelect').val($('#dateSelect').val()+all_dates);
   }});
  //Ajax call for image uploader
   });
 </script>

And then I have both elements:

 <div class="datePick"></div>


<input id="dateSelect" name="dateSelect" value=""/>
+1  A: 

To solve the problem, I changed the code in the onSelect event as follows:

   onSelect: function(date) 
   { 
    var all_dates = '';
          for (var i = 0; i < date.length; i++) 
            { 
              all_dates = all_dates + ':'+$.datepick.formatDate('yyyy-mm-dd', date[i]);
          } 
          $('#dateSelect').val(all_dates);
   }

I hope it helps.

dejavu
you sir, are a scholar and a gentleman. Works perfectly so far!
gamerzfuse
Thanks gamerzfuse for the compliment :)
dejavu