I have this:
signin_input.onkeypress = function()
{
label.style.opacity = 0;
}
but sometimes I want to run additional code so I overwrite it with this:
signin_input.onkeypress = function( event )
{
signin_label.style.opacity = 0; // just add in previous function here
if( event.keyCode === 13 )
{
new ControlType( 'signin' ).invoke();
return false;
}
}
and just include the one line from the old function in the new function.
However, this is a bit inefficient as I write to onkeypress twice.
Is there a way to have both run. Is there some sort of internal JavaScript construct that would allow this.
Start reading about DOM events…setting properties of elements is the ancient way…use
addEventListener()orremoveEventListener()for normal (meaning not IE family). Or useattachEvent()ordetachEvent()for IE6 ( and I suppose IE7 too )Best way…use some js library, I recommend jQuery.