With this code, a user enters values into various text fields and taps Save to save it to local storage (a persistent kind of HTML web page memory). Tapping Load will load the values back into the fields AND load the values of all the fields into a second textarea field as a summary for export.

I am using the following working code to do two things:
1. If a value HAS NOT been entered into the STwoDateFrom field in form2a, and the user taps Load, the field would correctly return "undefined" in the field. The if statement says to return a blank field instead. It works. The code also will also enter the field's caption on a new line in the second field called setupSTwoSummary in form2a.
2. But if a value HAS been entered into the STwoDateFrom field, the the else statement says to load the value into the original STwoDateFrom field AND enter the field's caption and value in the second field. This works.

Code JavaScript:
function loadDataS2()
{ "use strict";
 
var setup2SummariesString = ''; // default is no text added to the second field
var show2Summary = false; // default is don't show the field's value in the second field
 
setup2SummariesString += "--EVENT--\n  Date From: "; // concatenate this to a new line in the second field. "Date From" is the field caption.
    if (localStorage["local.storage22.STwoDateFrom"] === undefined) // if no value has been entered in the first field ...
    {
        document.form2b["STwoDateFrom"].value = ''; // ... then that field should show nothing, not even "undefined"
    }
    else
    {
        document.form2b["STwoDateFrom"].value = localStorage["local.storage22.STwoDateFrom"]; // load the value back into the first field
        setup2SummariesString += localStorage["local.storage22.STwoDateFrom"]; // also concaenate the value to the second field
        show2Summary = true;
    }
 
// write to field	
    if (show2Summary === true)
    {
        document.form2a["setupSTwoSummary"].value = setup2SummariesString; // write out concatenated string
    }
    else
    {
        document.form2a["setupSTwoSummary"].value = 'No content to display. Enter content in the fields for this setup and tap Save.'; // if no values in any of the fields, write this
    }
}

Now I want to adjust the code so that if no value is entered into the first field, I don't want anything added to the second field either. I tried the following change, but it still shows the new line and the field's name in the second field if the first field has no value entered. I don't know what else to try.

Code JavaScript:
setup2SummariesString += "--EVENT--";
    if (localStorage["local.storage22.STwoDateFrom"] === undefined)
    {
        document.form2b["STwoDateFrom"].value = '';
    }
    else
    {
        document.form2b["STwoDateFrom"].value = localStorage["local.storage22.STwoDateFrom"];
        setup2SummariesString += "\n  Date From: ";
        setup2SummariesString += localStorage["local.storage22.STwoDateFrom"];
        show2Summary = true;
    }