I have what on the face of it appears to be a simple question, however I am having some trouble with the solution. I am using asp.net 3.5 with jQuery1.8.3 and jQuery-confirm.
I will say at this point that javascript and jQuery are fairly new to me and I am not particularly confident using them.
I am intercepting the keydown event on a textbox and if the tab key has been pressed I show a jQuery-confirm dialog box. Following the action by the dialog box I wish to move to another textbox. Seems simple, here is my code.
$$("m_DiscountTextbox").on('keydown', function (e) {
var key = e.which || e.keyCode;
if (key == 9) {
PromptForDiscount();
document.getElementById($$("m_MarkupTextbox").attr("id")).focus();
}
});
function PromptForDiscount() {
$.confirm({
title: 'Apply global discount',
content: 'Discount will be applied to all line items. Click Confirm to continue, or Cancel to exit.',
boxWidth: '30%',
theme: 'material',
buttons: {
formSubmit: {
text: 'Confirm',
keys: 'enter',
btnClass: 'btn-blue',
action: function () {
ApplyDiscount();
}
},
cancel: function () {
}
},
useBootstrap: false
});
return false;
The $$ calls into a selector function that allows me to use the id of asp.net controls as they are before .net mangles them.
Using chrome developer tools I can see that the selectors are working throughout and have even set the text on the target textbox using them to check. It is simply the focus change that isn't working.
Initially the focus goes to the target and once the dialog is confirmed it reverts to the calling textbox. Any assistance would be appreciated with this.
Thanks in advance.
Further thoughts:
I am now wondering if it is the dialog passing control back to the original caller when it's operation is complete and in the process undoing the setting of focus on the next textbox. I have no evidence yet to back this up but it looks like it could be a candidate for investigation.
I have also set up a basic jsfiddle that demonstrates the issue: https://jsfiddle.net/8uap36fp/17/