views:

32

answers:

2

Hi My Dear Friends:

I Have A TextBox That i want do somthing(i am using it's text) with it's Text Change...

onkeyup - onkeypress - onkeydown not help because at first these events fire and then entering character applied(i want to use textbox text in changing it)

onchange not help because it is fired on blur...

what event should i use or how can i do that?

best regards

A: 

The onkeyup event fires after you've entered text:

onkeyup='alert(document.getElementById("myTextBox").value);'
Derek Hunziker
i do that / but it gives me the document.getElementById("myTextBox").Length-1 character / i hove not last entered character
LostLord
A: 

you want keyup, keydown, or a combination of them. during the keydown handler, you can get the before-event value of the textbox. during the keyup handler, you can get the after-event value. if you're getting an empty string you're doing something wrong.

edit: here's an example demonstrating how these 2 events works. typing in the first box updates the other two.

<table>
    <tr>
        <td>input</td>
        <td><input type="text" id="textin" /></td>
    </tr>
    <tr>
        <td>keydown</td>
        <td><input type="text" id="keydownout" /></td>
    </tr>
    <tr>
        <td>keyup</td>
        <td><input type="text" id="keyupout" /></td>
    </tr>
</table>
<script>

    var readbox = document.getElementById('textin');
    var keydownbox = document.getElementById('keydownout');
    var keyupbox = document.getElementById('keyupout');

    function keydownhandler(e) {
        keydownbox.value = readbox.value;
    }

    function keyuphandler(e) {
        keyupbox.value = readbox.value;
    }

    readbox.addEventListener('keydown', keydownhandler, false);
    readbox.addEventListener('keyup', keyuphandler, false);

</script>

(works in firefox/chrome)

lincolnk
really really thanks for your answers ....but it is still lost one character (last entered)some body told me to use setTimer in keyup event for getting textbox value!i don't doing is the best or not/any idea?
LostLord
i've updated my post with an example. if you're expecting a different behavior than the example provides, tell us what that might be.
lincolnk