I have a textbox where the user can enter in an account code. The textbox has an onblur
function to run some validation on the account code. The textbox also has a function for then the user double clicks on the textbox. This opens a screen that shows information on the account code.
<asp:TextBox runat="server" ID="txtAccountCode" CssClass="lookup" MaxLength="8" style="text-transform:uppercase" ondblclick="OpenCust(this.value)" onblur="CheckIfAccountCodeValid(this.value)"></asp:TextBox>
The problem is every time the user double clicks on the textbox it also runs the onblur
. Is there a way to stop running the onblur
when ondblclick
is called?
You could just remove the onBlur eventlistener in the OpenCust function.
Something like this in Vanilla JS:
document.getElementById('txtAccountCode').removeEventListener('ondblclick', CheckIfAccountCodeValid);
The issue is the order that the browser fires events. onblur
is triggered after onmousedown
, but before ondblclick
. My suggestion in order to keep things easiest as possible is to manage everything inside the ondblclik
, so something like this:
<asp:TextBox runat="server" ID="txtAccountCode" CssClass="lookup" MaxLength="8" style="text-transform:uppercase" ondblclick="OpenCustIfValid(this.value)"></asp:TextBox>
function OpenCustIfValid(value) {
if (CheckIfAccountCodeValid(value)) {
OpenCust(value);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.