The Code (Cont.): Updation


  Updating user #1
ref.on( "value", function( snapshot ) {
function(snapshot) is a callback or callback function, which is any reference to executable code that is passed as an argument to another piece of code such as the on method here; that code is expected to call back (execute) the callback function as part of its job.
<script>
 //
 // Function to get form values
 //
 function getInputVal( input ) {
  return document.getElementById( input ).value;
 }

 //
 // Update a user.
 //
 function updateUser( ) {
  // Get the input values.
  var ID     = getInputVal( 'ID' );
  var name2  = getInputVal( 'name' );
  var email2 = getInputVal( 'email' );
  var name3  = "";
  var email3 = "";
  var ref    = firebase.database( ).ref( 'users/' + ID );

  ref.on( "value",
   function( snapshot ) {
    const data = snapshot.val( );
    name3  = Object.values(data)[1];
    email3 = Object.values(data)[0];
    if ( name2  ) { name3  = name2;  }
    if ( email2 ) { email3 = email2; }
    ref.set( { name: name3, email: email3 } );
    var out  = ID + ": " + name3 + ", " + email3;
    document.getElementById( 'result' ).innerHTML = out;
   },
   function ( error ) {
    document.getElementById( 'result' ).innerHTML = "Error"; }
  )
  return( false );
 }
</script>





      What happens is not as important as how you react to what happens.    
      ― Ellen Glasgow