2

I have a (probably very stupid) question. I have a form I submit to my nodeJS server with Express. This works perfectly with text inputs and radiobuttons, but now I have to add a select. The server does not give an error but the select is not parsed properly.

my code:

<select id="chooselang">
<option value="nl" name="language">NL</option>
<option value="en" name="language">EN</option>
</select> 

and my server looks like this:

app.post('/settings', function(req, res){
// Fill JSON array with new settings
var myData = {
    ,name  : req.body.name
            ,mail : req.body.email
            ,language : req.body.language
    ,location: req.body.location
}
// Write to JSON file
fs.writeFile(configfilepath, JSON.stringify(myData, null, 4), function(err) {
    if(err) {
        res.send(500);
        console.log(err);
    } else {
        setTimeout(function () {
            res.redirect('back');
        }, 2000)
    }
}); 
});

Could someone please tell me what I'm doing wrong?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
jansmolders86
  • 5,449
  • 8
  • 37
  • 51

1 Answers1

8

Probably you will need to add a name attribute in your select and use that to capture the values.

Also, only one of the option values will be sent to the server, so there is no point in assigning name to each one of the options, if that was your intention.

MD Sayem Ahmed
  • 28,628
  • 27
  • 111
  • 178