function h(x)
{
alert(x);
}
<input onkeypress=h(this.value) type=text>
when i press 'a' alert empty
when i press 'b' after 'a' =>ab alert only 'a' and i want 'ab'
when i type 'abcd' it alert 'abc' only and i want 'abcd'
your event fires before letter is registered. you should use onkeyup event. It kicks-in after you release key