0

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

user1614862
  • 3,701
  • 7
  • 29
  • 46
  • *"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"* - What do you mean *Otherwise*? Even if `backbone syphone` plugin has some parse callback, you still have to manually add JavaScript code. what else do you expect? – T J May 14 '16 at 10:09
  • I can add some parse callback in syphone if it can handle this kind of fields across my application in different pages. "Otherwise" meant that if I could not handle it in syphone then I need to write and call this Javascript at least once in each of my pages. – user1614862 May 14 '16 at 10:22

1 Answers1

0

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;
}
T J
  • 42,762
  • 13
  • 83
  • 138
  • The javascript logic is fine, the main resolution that I am looking for is, how to combine them in general and treat them as a single field when submitted by user. I dont want call these JS functions for every date and time fields in my pages. I have 15 such fields in one of my pages. I was thinking "oninput" attribute. – user1614862 May 13 '16 at 22:31