I have a form with several date fields. These date fields are actual text fields as I want to control the date structure from the start.
<div class="form-group col-md-6 col-xs-13">
<?php echo form_error('eindDatum'); ?>
<label for="eindDatum"><?php echo $this->lang->line('eindDatum'); ?><small class="text-info"><?php echo ' ' . $this->lang->line('datumNotatie'); ?></small></label>
<input type="text" name="eindDatum" id="eindDatum" class="form-control date" placeholder="DD-MM-YYYY" required pattern="(0[1-9]|1[0-9]|2[0-9]|3[01])-(0[1-9]|1[012])-[0-9]{4}">
</div>
<div class="form-group col-md-6 col-xs-13">
<?php echo form_error('aanvangDatum'); ?>
<label for="aanvangDatum"><?php echo $this->lang->line('aanvangDatum'); ?><small class="text-info"><?php echo ' ' . $this->lang->line('datumNotatie'); ?></small></label>
<input type="text" name="aanvangDatum" id="aanvangDatum" class="form-control date" placeholder="DD-MM-YYYY" required pattern="(0[1-9]|1[0-9]|2[0-9]|3[01])-(0[1-9]|1[012])-[0-9]{4}">
</div>
I was looking for a formatter online to automatically insert the - (dash) between the structures. But my knowledge of JavaScript is really limited. I tried with using the class selector but that does not seem to work at all.
var date = document.getElementsByClassName('date');
And then I added a class of date to the input text fields
I (am trying to) work with this https://codepen.io/tutsplus/pen/KMWqRr
Any help would be greatly appreciated. If possible tell me why you are approaching it in a specific way so I can learn from your experience.