jeudi 23 juin 2016

JS Date Split not working for additional splits


I have the following code which works great for the time1 function. However once it hits time2 and time3 it ignores the splits and fields completely. Can anyone see why that may be? I am using distinct var names etc.. just not sure why the script works flawlessly for the first but not the others? Im using Bootstrap and Bootstrap datetimepicker if that helps.

<input type="hidden" id="incidentDate" value="" />
    <input type="hidden" id="incidentTime" value="" />
    <input type="hidden" id="alertCreationDate" value="" />
    <input type="hidden" id="alertCreationTime" value="" />
    <input type="hidden" id="procurementDate" value="" />
    <input type="hidden" id="procurementTime" value="" />

<label for="incidentDateTime">Incident Discovered?:</label><br/>  
        <div class="form-group">
            <div class='input-group date' id='incidentdiscovered'>
                <input type='text' name="incidentDateTime" id="incidentDateTime" class="form-control" value="" />
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
            </div>
        </div>

     <label for="creationAlert">Creation of Alert:</label><br/> 
      <div class="form-group">
            <div class='input-group date' id='alertCreation'>
                <input type='text' name="creationAlert" id="creationAlert" class="form-control" value="" />
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
            </div>
        </div>

<label for="procurementSolution">Procurement of workaround solution:</label><br/> 
     <div class="form-group">
            <div class='input-group date' id='procurement'>
                <input type='text' name="procurementSolution" id="procurementSolution" class="form-control" value="" />
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
            </div>
        </div>

//Date Time Split Function
         $(function () {
          function time1() {
            var dateTimeSplit = $('#incidentDateTime').val().split(' ');

            var dateSplit = dateTimeSplit[0].split('/');
            var currentDate = dateSplit[2] + '-' + dateSplit[0] + '-' + dateSplit[1];
            //currentDate is 18/10/2010

            $('#incidentDate').val(currentDate);

            var currentTime = dateTimeSplit[1] + ' ' + dateTimeSplit[2];
            //currentTime is 10:06 PM

            $('#incidentTime').val(currentTime);

            }
            $('#incidentdiscovered').on("dp.change", function () {
                time1();
            });

          });
          $(function () {
          function time2() {
            var dateTimeSplit2 = $('#creationAlert').val().split(' ');

            var dateSplit2 = dateTimeSplit2[0].split('/');
            var currentDate2 = dateSplit2[2] + '-' + dateSplit2[0] + '-' + dateSplit2[1];
            //currentDate is 18/10/2010

            $('#alertCreationDate').val(currentDate2);

            var currentTime2 = dateTimeSplit2[1] + ' ' + dateTimeSplit2[2];
            //currentTime is 10:06 PM

            $('#alertCreationTime').val(currentTime2);

            }
            $('#alertCreation').on("dp.change", function () {
                time2();
            });

          });
          $(function () {
          function time3() {
            var dateTimeSplit3 = $('#procurementSolution').val().split(' ');

            var dateSplit3 = dateTimeSplit2[0].split('/');
            var currentDate3 = dateSplit3[2] + '-' + dateSplit3[0] + '-' + dateSplit3[1];
            //currentDate is 18/10/2010

            $('#procurementDate').val(currentDate3);

            var currentTime3 = dateTimeSplit3[1] + ' ' + dateTimeSplit3[2];
            //currentTime is 10:06 PM

            $('#procurementTime').val(currentTime3);

            }
            $('#procurement').on("dp.change", function () {
                time3();
            });

          });

Aucun commentaire:

Enregistrer un commentaire