Javascript panel save txt

Hi
Of course, I m a very newbie,
I have a panel wich save my data to a txt file
Now it saves me only var txt1
How to save both variables, txt1 and txt2 to txt file
thank you very

var myWindow = new Window("dialog", "Form");
myWindow.orientation = "column";
myWindow.add("statictext", undefined, "Number:");

var t1 = getData()
var txt1 = myWindow.add("edittext", undefined, t1);

var t2 = getData()
var txt2 = myWindow.add("edittext", undefined, t2);


    var row3 = myWindow.add ("group");
    row3.add("button", undefined, "OK");
    row3.add("button", undefined, "Cancel");
    
    txt1.onChange = function () {
    saveData(txt1.text);
}


myWindow.show();

function getData() {
    var _data = '';
    var _file = File(Folder.myDocuments + "/data.txt");
    if (_file.exists) {
        _file.open("r");
        _data = _file.read();
    }
    return _data;
}

function saveData(text) {
    var _file = File(Folder.myDocuments + "/data.txt");
    _file.open("w");
    _file.write(text);
    _file.close();
}

You have it only for one of the two

yes, is only oneā€¦
but the question is
How to include ā€˜ā€™ txt2ā€™ā€™ to be saved like ā€œtxt1ā€, both Ć®n same file(data. txt)

You append it to the existing file, you would just write each bit of data to the same file.

However, as there isnā€™t any info as to what youā€™re using here (what provides those functions?) canā€™t really say what you need to do for that ā€“ I assume itā€™ll just be an extra argument to the write function but :man_shrugging:t3:

this is a simple panel. for now, I would like to save the 2 fields in a text file to retain this numbers for next useā€¦
but it only saves 1 field(230),
how to add the second field (150) in same txt file?

310-18-2021

Right, you are using JavaScript, but JS itself doesnā€™t have the functionality to do that: you are using some library which allows you to do it. But as I donā€™t know what library that is, itā€™s quite difficult to give any help. What are Window, Form and Folder?

ok, I understand
I thought they were the same rulesā€¦
I use extendscript toolkit

thank you

1 Like

you have this only for txt1, if you want to save both I would expect it also for txt2, or I would exect to see somewhere you concatenate the two as strings

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.