Meteor / MongoDB: insert an integer instead of a string in the submit form

I am working on a David Meteor tutorial at http://meteortips.com/ .

How to insert an integer instead of a string in a submit form?

I think the next line should make it clear that this is an integer, but I'm not sure how to do this.

var playerScoreVar = event.target.playerScore.value; 

Here is my whole code.

  Template.addPlayerForm.events({ 'submit form': function(event){ event.preventDefault(); var playerNameVar = event.target.playerName.value; var playerScoreVar = event.target.playerScore.value; PlayersList.insert({ name: playerNameVar, score: playerScoreVar, }); event.target.playerName.value = "" event.target.playerScore.value = "" } }); 
+5
source share
1 answer

Just convert it to an integer before insert :

 var playerScoreVar = parseInt(event.target.playerScore.value, 10); 

or

 var playerScoreVar = Number(event.target.playerScore.value); 

You can see the explained differences here ;

+4
source

All Articles