DavidRT49 DavidRT49 - 5 months ago 13
Node.js Question

nodeJS save post request of inputboxes in a file

var input = '';
for (i = 0; i < array.length; i++)
{
input += <input name=line_"+i+ " type=text >"+"\n";
}


This cycle create HTML input boxes depending on the length of an array
and saves these in the string "input".
For each of them I assign the name
"line_"
and the number of index
i
,
for example the name of first will be
line_0
, the second
line_1
etc.

if (req.url=='/postContent'){

var body='';
req.on('data', function (data) {
body += data;
});
req.on('end',function () {

var post = qs.parse(body);

for (i = 0; i < array.length; i++) {
fs.appendFile(databaseFile, "line"+i+": "+post.line_+"["+i+"]"+"\n");
}
res.writeHead(302, {
'Location': '/'
});
res.end();
});


Now when there is a post request in one of the input boxes I want to save this in a file. I try to write
post.line_+"["+i+"]
but the program does not find the name of input boxes in fact the result is this:

riga0: undefined[0]


How can I do to write
post.line_i
"i" in the sense of variable.
thanks.

Answer

Did you try this?

post['line_' + i]

Comments