Skip to main content
07cc07
Participating Frequently
November 19, 2018
Question

Javascript: How to extract data from 2 fields into 1?

  • November 19, 2018
  • 2 replies
  • 934 views

I am trying to extract a start date and return date into one field to show travel date. These text-boxes are formatted as Date fields except for Travel Date. one is (departure) and the other is (return). I want to extract these two fields into one field so that the travel date text-box is: ("departure" - "return").

Below is what I currently have however it is not working.

var sDate = this.getField("text4").value;

var rDate = this.getField("text15").value;

var tDate = this.getField("dateTravel").value;

tDate.value = sDate.value + " - " + rDate.value;

This topic has been closed for replies.

2 replies

07cc07
07cc07Author
Participating Frequently
November 26, 2018

correct code:

var sDate = getField("Depart_Date");

var rDate = getField("Return_Date");

var tDate = getField("Travel_Date");

tDate.value = sDate.value + " - " + rDate.value;

place this Javascript code under the "Return_Date" textbox

try67
Community Expert
Community Expert
November 26, 2018

That's not a good way of doing it. It means that it won't update the "Travel_Date" field when you update the "Depart_Date" field, for example.

Instead of doing it like that change the code to this and put it under the calculation event of the "Travel_Date" field:

var sDate = getField("Depart_Date");

var rDate = getField("Return_Date");

event.value = sDate.value + " - " + rDate.value;

07cc07
07cc07Author
Participating Frequently
November 26, 2018

Thank you!!! How would you go about creating date validation so that "Depart_Date < Return_Date" always?

Karl Heinz  Kremer
Community Expert
Community Expert
November 19, 2018

You almost have it:

Use the following as the custom calculation script in your target field:

event.value = sDate + " - " + rDate;

You already got the value property of the field, so you don't have to do that again when you concatenate your strings.

07cc07
07cc07Author
Participating Frequently
November 19, 2018

I tried that however data is still not filling in the dateTravel text-box. Do you think It might be because I have the sDate & rDate text-boxes formatted as date fields?

try67
Community Expert
Community Expert
November 19, 2018

No, that's not it. Check the JS Console (Ctrl+J) for error messages, though.