problem fetching value of <input type="text"...

Discussion in 'HTML' started by Smugsboy, Nov 30, 2005.

  1. Smugsboy

    Smugsboy Guest

    Got a problem here, hope someone can help.
    I want to fetch edit box's (<input type="text"...) value string upon
    change. What I do is I attach handler to the onkeypress event. I have
    two issues with this:

    1. When the onkeypress handler executes I do not get the latest char
    that was pressed (if the 't' char for "cat" was pressed I'll only get
    "ca"), this is true for both IE & Firefox. Is there any solution to
    this ? I need a solution that will work both on IE & Firefox.

    2. Is there a more through event I should attach to ? because using
    only the onkeypress I miss copy-paste operations.

    Thanks,
    Smugsboy, Nov 30, 2005
    #1
    1. Advertising

  2. Smugsboy

    Steve Pugh Guest

    Smugsboy wrote:
    > Got a problem here, hope someone can help.
    > I want to fetch edit box's (<input type="text"...) value string upon
    > change. What I do is I attach handler to the onkeypress event. I have
    > two issues with this:
    >
    > 1. When the onkeypress handler executes I do not get the latest char
    > that was pressed (if the 't' char for "cat" was pressed I'll only get
    > "ca"), this is true for both IE & Firefox. Is there any solution to
    > this ? I need a solution that will work both on IE & Firefox.


    Depends on the order of events I suppose. Looks like the keypress event
    takes place before the content of the input is changed. the onkeypress
    event isn't really the best tool for the job...

    > 2. Is there a more through event I should attach to ? because using
    > only the onkeypress I miss copy-paste operations.


    onchange

    Steve
    Steve Pugh, Nov 30, 2005
    #2
    1. Advertising

  3. Smugsboy

    Smugsboy Guest

    onchange captures focus change and not not value change in <input
    type="text"
    So it doesn't help me much.

    Thanks,
    Smugsboy, Nov 30, 2005
    #3
  4. Steve Pugh wrote:
    > Smugsboy wrote:
    >
    >>Got a problem here, hope someone can help.
    >>I want to fetch edit box's (<input type="text"...) value string upon
    >>change. What I do is I attach handler to the onkeypress event. I have
    >>two issues with this:
    >>
    >>1. When the onkeypress handler executes I do not get the latest char
    >>that was pressed (if the 't' char for "cat" was pressed I'll only get
    >>"ca"), this is true for both IE & Firefox. Is there any solution to
    >>this ? I need a solution that will work both on IE & Firefox.

    >
    >
    > Depends on the order of events I suppose. Looks like the keypress event
    > takes place before the content of the input is changed. the onkeypress
    > event isn't really the best tool for the job...
    >
    >
    >>2. Is there a more through event I should attach to ? because using
    >>only the onkeypress I miss copy-paste operations.

    >
    >
    > onchange


    'onchange' with fire after user presses 'enter' or leaves the field as
    with an 'onblur'. Sounds like the behavior that the OP seeks is
    'onkeyup' which fires AFTER the key is pressed. My understanding is
    'onkeyup' has checkered support...others may have more info on the subject.


    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
    Jonathan N. Little, Nov 30, 2005
    #4
  5. Smugsboy

    Smugsboy Guest

    Jonhathan,
    What do you mean by "checkered support" ?
    If I use the onkeyup, will it respond for every char input (even if I
    press a long keystroke which translates to several input characters) ?
    Are the event the same in IE/FF?

    Thanks,

    Jonathan N. Little wrote:
    > Steve Pugh wrote:
    > > Smugsboy wrote:
    > >
    > >>Got a problem here, hope someone can help.
    > >>I want to fetch edit box's (<input type="text"...) value string upon
    > >>change. What I do is I attach handler to the onkeypress event. I have
    > >>two issues with this:
    > >>
    > >>1. When the onkeypress handler executes I do not get the latest char
    > >>that was pressed (if the 't' char for "cat" was pressed I'll only get
    > >>"ca"), this is true for both IE & Firefox. Is there any solution to
    > >>this ? I need a solution that will work both on IE & Firefox.

    > >
    > >
    > > Depends on the order of events I suppose. Looks like the keypress event
    > > takes place before the content of the input is changed. the onkeypress
    > > event isn't really the best tool for the job...
    > >
    > >
    > >>2. Is there a more through event I should attach to ? because using
    > >>only the onkeypress I miss copy-paste operations.

    > >
    > >
    > > onchange

    >
    > 'onchange' with fire after user presses 'enter' or leaves the field as
    > with an 'onblur'. Sounds like the behavior that the OP seeks is
    > 'onkeyup' which fires AFTER the key is pressed. My understanding is
    > 'onkeyup' has checkered support...others may have more info on the subject.
    >
    >
    > --
    > Take care,
    >
    > Jonathan
    > -------------------
    > LITTLE WORKS STUDIO
    > http://www.LittleWorksStudio.com
    Smugsboy, Nov 30, 2005
    #5
  6. Smugsboy wrote:
    > Jonhathan,


    Hi Smugsboy,

    Firstly if you peruse the newsgroup you will notice that TOP POSTING is
    frowned upon, write responses below quoted material.

    > What do you mean by "checkered support" ?


    onkeyup should be supported in modern browsers, was an issue in the past.

    > If I use the onkeyup, will it respond for every char input (even if I
    > press a long keystroke which translates to several input characters) ?


    Every time the key is released the event fires,

    'long keystroke' ?? Do you mean where you hold the key down and the
    'type-o-matic' repeat on character occurs? Again it fires when the key
    go up.

    Demo may help explain:

    <html>
    <head>
    <title>TestBed</title>
    <script type="text/javascript">
    function test(ff){
    var f=ff.form;
    f.myout.value=ff.value;
    }
    </script>
    </head>
    <body>
    <form>
    in <input type="text" size="30" name="myin" onkeyup="test(this)"><br>
    out <input type="text" size="30" name="myout"><br>
    </form>
    </body>
    </html>


    > Are the event the same in IE/FF?

    <snip>






    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
    Jonathan N. Little, Nov 30, 2005
    #6
  7. In article <>,
    says...
    > onchange captures focus change


    It doesn't.

    > and not not value change in <input type="text"


    Yes, it does. That's why it's called "onchange".

    Quote the post you're replying, too.

    --

    Hywel
    http://kibo.org.uk/
    Hywel Jenkins, Nov 30, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bhavesh
    Replies:
    0
    Views:
    408
    Bhavesh
    Jul 16, 2007
  2. Bhavesh
    Replies:
    5
    Views:
    602
    Bhavesh
    Jul 18, 2007
  3. Bhavesh
    Replies:
    1
    Views:
    436
    Bhavesh
    Jul 17, 2007
  4. Bhavesh
    Replies:
    1
    Views:
    400
    Bhavesh
    Jul 17, 2007
  5. Nitin

    problem fetching *only one* value.

    Nitin, Sep 17, 2004, in forum: Perl Misc
    Replies:
    2
    Views:
    84
    Joe Smith
    Sep 19, 2004
Loading...

Share This Page