Suga24
Suga24

Reputation: 55

Capture the previous value when onkeydown is executed

Need help in event handling. In my scenario, I have a textbox with default value 35 and cursor is set to before the 3. There is a event for this text box which is onkeydown. When I press 4, IE and Safari captures the previous value of the text which is 35. But Mozilla and Chrome captures the new value which is 435.

I need the javascript code which can capture the previous value of the textbox when onkeydown is fired.

Need your hands :(

Upvotes: 1

Views: 171

Answers (1)

Usman
Usman

Reputation: 3278

Tested in IE, Chrome, FF, Opera and it works

<div>
    <input type="text" value="35" />
</div>
<script>
       $("input").keydown(function () {
            alert($(this).val());
        });
</script>

Upvotes: 3

Related Questions