0

I have a textbox that receives realtime data from realtime firebase database. This is how the textbox is being updated

function getUpdate(id) {
    var updatedRef = firebase.database().ref('operators/' + id);

        updatedRef.on('value', function(snapshot) {
            document.getElementById('txt_lastmsg').value = snapshot.child("msg").val();
        });
}

window.onload = getUpdate(0);

The textbox is working properly and getting new data every time firebase is updated.

I tried to attached onChange on the textbox but it is not being fired by the firebase update.

<input type="text" id="txt_lastmsg" onchange="javascript:alert('Hello World!')"><br>

How can I detect the firebase update on the textbox?

Thanks

Wayne
  • 763
  • 4
  • 21
  • 43
  • "I tried to attached onChange on the textbox but it is not being fired" Please edit your question to include the code that you used to try this. – Frank van Puffelen Nov 30 '19 at 15:21
  • @FrankvanPuffelen onChange code added – Wayne Nov 30 '19 at 15:59
  • There is no built-in way to detect a change of the input's value through code. You can either simply add/code the additional code after your existing `document.getElementById('txt_lastmsg').value = ...`, or take one of these solutions: https://stackoverflow.com/questions/42427606/event-when-input-value-is-changed-by-javascript – Frank van Puffelen Nov 30 '19 at 16:46

1 Answers1

0

Do you use jQuery?

If so try the change() function

$("#txt_lastmsg").change(function(){
    alert("The text has been changed.");
});