<label for="input"></label>
<input type="text" id="input" />
(function ( input ) {
var label, oldValue = '';
var labels = document.getElementsByTagName("label");
for ( var j = 0; label = labels[j++]; ) {
if ( label.getAttribute("for") == input.id ) { break; }
}
if ( !label ) { return; }
function handler() {
if ( input.value != oldValue ) {
oldValue = value;
label.innerHTML = "";
label.appendChild( document.createTextNode( value ) );
}
};
if ( input.addEventListener ) {
input.addEventListener( "keyup", handler, false );
input.addEventListener( "keydown", handler, false );
} else if ( input.attachEvent ) {
input.attachEvent( "onkeyup", handler );
input.attachEvent( "onkeydown", handler );
} else {
input['onkeyup'] = input['onkeydown'] = handler;
}
})( document.getElementById('input') );