Created
December 5, 2014 14:13
-
-
Save tarzak/fc4f1c71ea3a7e5e1181 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Template.simpleCounter.rendered = function () { | |
var btn = document.getElementById('btn'), | |
input = document.getElementById('input'), | |
sum = Money.findOne({name: "Total"}).total, | |
tmp = 0, | |
totalId; | |
totalId = Money.findOne({name: "Total"})._id; | |
console.log(sum); | |
btn.addEventListener("click", function () { | |
if(Meteor.userId()){ | |
tmp = parseInt(input.value); | |
if(isNaN(tmp)) { | |
alert('Enter a number please!'); | |
} | |
else{ | |
console.log(tmp); | |
sum = sum + tmp; | |
console.log(sum); | |
input.value = ""; | |
Money.update({_id: totalId},{$set: {total: sum}}); | |
} | |
} | |
else { | |
alert("Log in please!") | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment