Created
September 25, 2017 18:16
-
-
Save sheminusminus/04bc499fd76ea60a1659277d9ac5de85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// assuming you have radio inputs like this in your html: | |
// <input type="radio" name="gender" value="1"> Female | |
// <input type="radio" name="gender" value="2"> Male | |
// you can do something like this serverside: | |
function getGenderForInteger(genderInt) { | |
switch (genderInt) { | |
case 1: // handling the case where genderInt === 1 | |
return 'Female'; | |
case 2: // handling the case where genderInt === 2 | |
return 'Male'; | |
default: // required fallback (e.g. genderInt === 3, 4, etc? will return male) | |
return 'Male'; | |
} | |
} | |
// and something similar to that ^ for other types of integer data you need to stringify | |
// and just get the string by passing the form value into above function: | |
app.post('/survey', function (req, res, next) { | |
let gender = getGenderForInteger(req.body.gender); | |
// ... the rest of your req.body values ... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment