I'm trying to get the value from specific child in firebase and as I see it there is nothing wrong with the code.
When I create an alert inside reciverbitconvalue menu
it works but when I pass it through another string and make an alert for that string it doesn't work, it says it's undefined
.
For example please check reciverbitconvalue
and you will realize I passed snapshoot
to another string called passbitcoin
and then I passed it to an alert and when I run it it says it's undefined
.
var senderbitcoinvalue;
var formbitcoinamount;
var formbitcoinuid;
var subtractbitcoin;
var passbitcoin;
var passbrecevier;
var divisionbitcoin;
document.getElementById("sendbitcoin").addEventListener("click", function() {
//form values
formbitcoinamount = document.getElementById("bitcoinamount").value;
formbitcoinuid = document.getElementById("bitcoinuid").value;
var senderbitcoinvalue = firebase.database().ref().child("users").child(uid).child("bitcoin");
senderbitcoinvalue.on('value', function(databasesnapshot) {
//pass bitcoin
passbitcoin = databasesnapshot.val();
});
var reciverbitconvalue = firebase.database().ref().child("users").child(formbitcoinuid).child("bitcoin");
reciverbitconvalue.on('value', function(databasesnapshot122) {
//pass bitcoin
passbrecevier = databasesnapshot122.val();
});
if (passbitcoin > formbitcoinamount) {
subtractbitcoin = passbitcoin - formbitcoinamount;
// put subtracted amount on sender value
var senderbitcoinsub = firebase.database().ref();
senderbitcoinsub.child("users").child(uid).child("bitcoin").set(subtractbitcoin);
//reciver value
alert(passbrecevier);
alert("Your amount successfully been transferred");
return;
} else {
alert("You dont have enough Bitcoins");
}
});