<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>
|