I'm working through David's tutorial on Meteor at http://meteortips.com/.
How do I insert an integer instead of string on form submit?
I think the following line needs to clarify that it's an integer, but I'm not sure how.
var playerScoreVar = event.target.playerScore.value;
Here's 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 = ""
}
});
Just convert it to an integer prior to the insert
:
var playerScoreVar = parseInt(event.target.playerScore.value, 10);
or
var playerScoreVar = Number(event.target.playerScore.value);
You can see the differences explained here;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With