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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:33:38+00:00 2026-06-17T05:33:38+00:00

I have defined focus event of a form field to open a Jquery UI

  • 0

I have defined focus event of a form field to open a Jquery UI dialog with options to select. I want that focus should stay on same field for un-interrupted data entry. My requirement is just like as shown by datepicker, user sees datepicker overlay but focus stays on date field so that user can continue to type in the date.

Here is code for relevant field and dialog.

$( "#pmt_code" ).focus(function(){
    $( "#pmtcodes" ).dialog( "open" );
    // Keep focus stayed on this field somehow
  });


$( "#pmtcodes" ).dialog({
    autoOpen: false,
    position: { my: "left top", at: "left bottom", of: $("#pmt_code") },
    closeOnEscape: true,
    open: function(){
      listPmtCodes();
    }        
  });

Here is the Dialog Div with table. I am populating this table using jquery datatable plugin.

<div id="pmtcodes" title="payment Codes">
      <table cellpadding="0" cellspacing="0" border="0" class="display" id="pmtCodesTable">
        <thead>
          <tr>
            <th>Code</th>
            <th>Description</th>
          </tr>
        </thead>
        <tbody>
        </tbody>
      </table>        
    </div>
  • 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-17T05:33:39+00:00Added an answer on June 17, 2026 at 5:33 am

    You must set the focus to your control again on the open callback:

    var $pmt_code = $("#pmt_code"),
        $pmtcodes = $("#pmtcodes");
    
    $pmt_code.focus(function(){
        !$pmtcodes.dialog( "isOpen" ) && $pmtcodes.dialog( "open" );
    });
    
    $pmtcodes.dialog({
        autoOpen: false,
        position: { 
            my: "left top", 
            at: "left bottom", 
            of: $pmt_code 
        },
        closeOnEscape: true,
        open: function(){
            listPmtCodes();
            setTimeout(function () { // Workaround for Internet Explorer
                $pmt_code.focus(); //<---- Keep focus stayed on this field somehow
            }, 10);
        }
     });
    

    I just changed the code a little to avoid searching on DOM more then once for each element.

    You also need to implements the keyup event to catch the ESC pressed to close the dialog:

    $pmt_code.keyup(function (e) {
        if (e.keyCode == 27 && $pmtcodes.dialog("isOpen")) // ESC pressed
        {
            $pmtcodes.dialog("close");
        }
    });
    

    Check one live here: http://jsfiddle.net/9KuVA/

    I hope this can helps

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

Sidebar

Related Questions

I have defined CSS in MasterPage so that all pages can use the same
I have defined some events when input textbox has got focus and some task
I have a MouseDoubleClick event handler defined in a ListView.ItemContainerStyle definition as such: <ListView.ItemContainerStyle>
I have a WPF application where I have defined custom commands that use the
I have a control template defined, call it myVal, that is used for validation
I have a jQuery search script that uses tabs for the user to define
I hope this is a simple problem. I have a seekbar that I want
I want to use a jQuery UI dialog to display the errors in the
I have a ListBox and it has a DrawItem event defined as follows. The
I have defined following control template for my custom control. <ControlTemplate TargetType={x:Type local:CustomControl}> <Grid

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.