Edit in JSFiddle

function runExample(demoUrl) {
    
    var ref = new Firebase(demoUrl);
    $('button').click(function () {
        var val = $('input').val();
        ref.set(val, result);
    });
    $('input').on('keyup', countChars);
    
    function result(err) {
        if( err ) {
            $('p.result').removeClass('success').text(err.code);
        }
        else {
           $('p.result').addClass('success').text('success!');   
        }
    }
    
    function countChars() {
       $('label').text( $(this).val().length + ' characters');   
    }
    
    // show the current value
    ref.on('value', log);
    function log(snap) {
        $('span').text(JSON.stringify(snap.val(), null, 2));
    }

}

// Dependencies used in this fiddle:
// code.jquery.com/jquery-2.1.0.min.js
// cdn-gh.firebase.com/demo-utils-script/demo-utils.js
//
// This line creates a unique, private Firebase URL 
// you can hack in! Have fun!
$.loadSandbox('web/sec/validate-example').then(runExample);