I have an input field which on entering the input and clicking the save button, the data should be saved in the firebase storage. The code is as below,
<div class="md-form">
<input type="number" id="ip1" class="form-control">
<label for="ip1">ip1</label>
</div>
<button type="button" id="ip1_btn" class="btn btn-dark-green">SAVE</button>
Below is what I am trying to achieve using js,
var rootRef = firebase.database().ref().child('demo-260b2');
$('#ip1_btn').click(function(){
rootRef.set({
ip1:$('ip1').val()
});
})
While trying on the browser, I am getting the following error,
Uncaught Error: Reference.set failed: First argument contains undefined in property 'demo-260b2.ip1'
I am unable to figure out what's wrong in this. Any help would be very much helpful.
The error message is telling you that you provided a value of undefined
somewhere in the object to set. The only value you have here is from $('ip1').val()
. I would conclude that value is actually undefined. You should log/debug it to see for yourself.
My guess is that you meant to use this instead: $('#ip1').val()
. Note the #
in front of "ip1", which would call out the element with the HTML id "ip1".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.