show/hide datepicker when checkbox is ticked

chrissy6930 27 May, 2014
hi all,

I would like to show/hide mootools datepicker ONLY if a checkbox has been ticked

in analogy to this link I created a load JS and inserted it before the custom datepicker

var checkbox_id, date_picker_id, checkbox, date_picker, div;
/* edit the next two lines to match the ids of the elements in your form */
checkbox_id = 'checkbox';
date_picker_id = 'date_picker';

window.addEvent('domready', function() {
  checkbox = $(checkbox_id);
  date_picker = $(date_picker_id);
  div = $(date_picker_id+'_container_div');
  div.dissolve();
  showHide();
  checkbox.addEvent('click', showHide);
});

function showHide() {
  if ( checkbox.checked ) {
    div.reveal();
    date_picker.disabled = false;
  } else {
    div.dissolve();
    date_picker.value = '';
    date_picker.disabled = true;
  }
}


the respective IDs have been entered to the checkbox and datetime picker

I suppose part of the prob is that the datepicker is to be set as required...
and it should be required once the checkbox is ticked (default value is set to 00-00-0000 00:00:00)

is there any way I could get this to work?
GreyHead 27 May, 2014
Hi chrissy6930,

Please post a link to the form so I can take a quick look.

Bob
This topic is locked and no more replies can be posted.