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 8241477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:50:56+00:00 2026-06-07T20:50:56+00:00

I have a simple form which I would like to submit (i.e fire ajax)

  • 0

I have a simple form which I would like to submit (i.e fire ajax) when the user presses enter (return) on an input field. If I press the submit button the event fires fine, but when using keyup to fire the exact same function the value of the input field is blank. I tried passing the value of the input field (from the keyup function) using $(this).val(), but the passed param was still blank.

Update II: The problem only occours on initial load. After hitting refresh the events fire as intended. Tested in Chrome and FF.

http://jsfiddle.net/R5QsC/1/

// Value of #pin is blank in getKeyAjax()
$('#pin').keyup(function(e) {
    if (e.keyCode == 13) {
        console.log('DEBUG: Keypress detected (13)')
        getKeyAjax();
    }
});
// Value of #pin is correct in getKeyAjax()
$('#btnPwdCreate').click(function() {
    getKeyAjax();
});

function getKeyAjax() {
    console.log('DEBUG: Starting ... getKeyAjax()');
    var txtPin = $('#pin').val();
    console.log('DEBUG: Value of txtPin: ' + txtPin);
   .
   .
   .
}
  • 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-07T20:50:58+00:00Added an answer on June 7, 2026 at 8:50 pm

    I noticed on your fiddle one thing that might be causing this. In using the form field I noticed that sometimes I got an alert stating ‘4 digits only’ and usually I did not. The problem there is your form tag. Hitting enter is triggering the browser’s default behavior: a non ajax form submit. If this goes through before your $.GET has run, it would be consistent with the behavior you described, after refresh the js is cached and then might evaluate faster allowing the $.get just before the submit and refresh occurs. Its just a theory, but ultimately it leaves you with two options:

    1. remove the <form> tag from your html.
    2. $('form').on('submit', function(e){e.preventDefault();});

    1# will have the effect of no default submits because there is no <form> to do so. 2# overrides the onsubmit event to prevent the default submit (letting you keep the form tag).

    Whether this solves the problem you are after or not, you do need it for your script regardless. Its going to be key to performing ajax while hitting enter on an input inside a form.

    http://jsfiddle.net/9TYhT/

    Fiddle above. Behavior is now consistent.

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

Sidebar

Related Questions

I have simple form like this which accepts only two values string action and
I have a simple modal form which I'd like to close when Esc is
I have an ajax form in asp.net mvc which is as simple as this:
I have a simple form that I would like to validate on form submission.
I have a simple form (textbox, submit button) which is wrapped in an update
I have written a simple CRUD form which has one select list. However the
I have a simple Ruby on Rails form which includes an authenticity_token. Unfortunatly, I
I have a simple MVC form with the following elements: <%= Html.TextBox(FechaInicio) %> Which
I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input
I have a simple form that looks like so <% remote_form_for post, :url =>

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.