Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8389661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:47:19+00:00 2026-06-09T18:47:19+00:00

How do I obtain the value of a textbox after an OnKeyPress event? For

  • 0

How do I obtain the value of a textbox after an OnKeyPress event? For example, Let’s say I have the following code:

<input type = "number" id = "foo" onKeyPress = "submit();"/>
<script type = "text/javascript">
function submit()
{
var textValue = document.getElementById("foo").value;
alert(textValue);
}
</script>

Unfortunately, this doesn’t work because after the OnKeyPress is triggered, the variable textValue will still be one character behind. I would use OnKeyUp, but sadly it doesn’t work on Android devices unless the <input type = "text"> which doesn’t work in my situation… Does anyone know a way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:47:21+00:00Added an answer on June 9, 2026 at 6:47 pm

    If the only problem is Android devices, I suggest using onkeyup for everyone else. Then you can detect if it’s android (or if keyup is supported on the input) and, if necessary, implement an Android specific solution.

    function submit(){
        function submitNow() {
            var textValue = document.getElementById("foo").value;
            alert(textValue);
        }   
        if(isAndroid) {
            setTimeout(submitNow, 10);
        }
        else {
            submitNow() ;
        }
    }
    
    var isAndroid = navigator.userAgent.toLowerCase().indexOf("android") > -1; 
    var eventType = (isAndroid) ? "keyup" : "keypress" ;
    document.getElementById("foo").addEventListener(EventType, submit);
    

    You can then remove the onKeyPress = "submit();" from your input.

    When not on Android, this code will act normally, using the keyup event. When the client is on Android, it will wait for 1/100th of a second, enough time for the input to update, but too short to be noticeable.

    Normally, I’d warn against long key presses, but I’m not aware of an Android keyboard that supports them.

    Android solution only:

    function submit(){
        function submitNow() {
            var textValue = document.getElementById("foo").value;
            alert(textValue);
        }   
        setTimeout(submitNow, 10);
    }
    
    document.getElementById("foo").addEventListener("keyup", submit);
    

    You could even keep your onKeyPress = "submit();" if you really felt like it. Just remove the last line here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form with the following dynamically added row: <input type=text name=statuseffective id=statuseffective_0
I wonder how to obtain feedback from an event? Situation: Let's say that a
In the following example this[] is used within a class to obtain a value
Please, let me give an example. Say, we have: a CheckedListBox control enumerating names
I have an overloaded generic method used to obtain the value of a property
In this code, we can obtain value of element id as 2 differnt way
How does index in the below example obtain its value? I understand that n
i have a problem with FCK editor. i want to obtain a value in
Whats the servlet syntax to obtain parameter value that comes after the question mark
I have the following code below, that is working for the most part. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.