Control and Combine Html Form fields before submitting

253 views Asked by At

I have a html form with date and time fields separately, when user clicks on save button I want to combine both date and time into date field and submit only date field with combined date and time. I already have "skip_element" attribute which I can use to avoid submitting of any field by setting true or false. My major requirement is I want to combine the date and time field values into one field and submit the form. I have backbone syphone to serialize the form. Can I do something there to combine the date and time field values and removing the time field?

Otherwise, I need to do manual coding in javascript function to combine these two fields and removing the time field from my array before sending dates with times to server. And I have to do it in many pages of my application. If it can be achieved in simple way that would be great.

enter image description here

1

There are 1 answers

1
Terence Hoefdraad On

You will probably need something like this.

function passDateAndTime () {
  var date = '05/10/2015';
  var time = '05:00:00 AM'; //the time wil need to be a date object, The time field will probably yield the correct time format.
  var date_time = joinDateAndTime_(date, time);
  Logger.log('date and time: ' + date_time);

  }

function joinDateAndTime_(date, time) {
  var date = new Date(date); Logger.log('date: ' + date);
  date.setHours(time.getHours());
  date.setMinutes(time.getMinutes());
  return date;
}