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

  • Home
  • SEARCH
  • 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 3873718
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:04:09+00:00 2026-05-19T22:04:09+00:00

Currently I have an HTML form with a hidden field right before a text

  • 0

Currently I have an HTML form with a hidden field right before a text input. A simplified version is below:

<form>
    <input type="hidden" name="key" id="key" />
    <input type="text" name="account" id="account" />
    <input type="button" value="Submit" />
</form>

The text input has been decorated with the jQuery UI Autocomplete.

$("#account").click(function () {
    $(this).prev().val('');
    $(this).val('');
}).autocomplete({
    source: function (request, response) {
        $.ajax({
            url: "AJAX.asmx/GetAccounts",
            data: "{ 'Search': '" + request.term + "' }",
            dataType: "json",
            type: "POST",
            contentType: "application/json; charset=utf-8",
            dataFilter: function (data) { return data; },
            success: function (data) {
                response($.map(data.d, function (item) {
                    return {
                        value: item.Value,
                        key: item.Key
                    }
                }))
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(textStatus + ": " + errorThrown);
            }
        });
    },
    select: function (event, ui) {
        $(this).prev().val(ui.item.key);
    },
    change: function (event, ui) {
        if ($(this).prev().val() == '') {
            $(this).val('');
        }
    }
});

The script above functions perfectly, except for when a user copy and pastes information into it. Most users will copy and paste and hit Submit well before the AJAX account search has even finsihed. The user does not know that the script needs them to select a result from the drop down or else the hidden field will not populate. However, most users are impatient and want to do things with minimal clicking.

How can I intercept a paste that has one result? How can I do this before the user clicks the submit button?

  • 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-05-19T22:04:09+00:00Added an answer on May 19, 2026 at 10:04 pm

    A simple way to enforce selecting from the autocomplete menu is to intercept the form’s submit event and return false unless #key has something in it.

    //assuming there is only one form within web page
    $('form').submit(
        function(){
            if($('#key').val() == '') {
                return false
            } else {
                return true
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an HTML form, to which I dynamically add a text field and
I have a form in HTML with multiple inputs of type submit: <form id
I have 2 sets of 4 input fields in my HTML Form. I expect
Is it legal to have an HTML form with more than one hidden control
I currently have a small HTML form for a third party payment service, which
In my view I currently have the following code: <%= Html.Hidden(Cart.CartID, Model.Cart.CartID) %> When
I currently have two apps: app1/ app2/ templates/ app1.html app2.html In app1.html, I'm including
I currently have the following MySQL statement to replace the HTML entity for a
I currently have a product view page that contains an MVCContrib HTML Grid with
I have an html table with many rows. I'm currently grouping several rows inside

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.