Try using a timer:
const id = "mobileno"; const element = document.getElementById(id); if (element.value.length >= 10) { alert("Mobile Number Should be in 10 digits only"); element.value = ""; window.setTimeout(() => element.focus(), 0); return false; }
A timer with a count of 0 will run when the thread becomes idle. If that doesn’t help, try the code (with the timer) in the onblur
event instead.
Related Posts:
- Javascript split regex question
- Find object by id in an array of JavaScript objects
- Cannot set property InnerHTML of null [duplicate]
- How can I submit a form using JavaScript?
- How do I get the current date in JavaScript?
- How to do a redirect to another route with react-router?
- Jest spy on functionality
- Use a JSON array with objects with javascript
- How do I empty an array in JavaScript?
- JavaScript TypeError: Cannot read property ‘style’ of null
- JavaScript string newline character?
- How to create a GUID / UUID
- How does “/\s/g” replace spaces with other characters?
- What is the correct way to check for string equality in JavaScript?
- JavaScript TypeError: Cannot read property ‘style’ of null
- How to obtain username from Promise
? - Number converted in 1e+30
- Static variables in JavaScript
- ReferenceError : window is not defined at object.
Node.js - Node.js Port 3000 already in use but it actually isn’t?
- Uncaught TypeError: $.post is not a function
- Unable to verify leaf signature
- When and why to ‘return false’ in JavaScript?
- XML Parsing Error: no root element found Location in Console FF
- TypeError: app.use() requires middleware functions
- Possible to extend types in Typescript?
- JavaScript enumerator?
- How to format numbers as currency strings
- Understanding how data-dismiss attribute works in Bootstrap
- Add table row in jQuery
- Node.js document is not defined
- Create table with jQuery – append
- Obtain form input fields using jQuery?
- Npm install cannot find module ‘semver’
- How to download a file with Node.js (without using third-party libraries)?
- Getting current date and time in JavaScript
- What is ViewChild in Angular2?
- Permutations in JavaScript?
- How do I remove documents using Node.js Mongoose?
- node-request – Getting error “SSL23_GET_SERVER_HELLO:unknown protocol”
- jQuery make global variable
- Mixed Content Page: requested an insecure stylesheet error
- How to do integer division in javascript (Getting division answer in int not float)?
- javascript unexpected identifier
- How to send email by using javascript or jquery
- Access to Image from origin ‘null’ has been blocked by CORS policy
- Onclick on bootstrap button
- TypeError: res.json is not a function
- How to run a function when the page is loaded?
- Convert normal date to unix timestamp
- jQuery replace one class with another
- Clearing my form inputs after submission
- Scope Chain in Javascript
- Changing the image source using jQuery
- Reload an iframe with jQuery
- JavaScript pattern for multiple constructors
- How to manage a redirect request after a jQuery Ajax call
- how to write javascript code inside php
- javascript convert int to float
- Uncaught TypeError: Cannot read property ‘toLowerCase’ of undefined
- How do I convert a JavaScript forEach loop/function to CoffeeScript
- ZIP Code (US Postal Code) validation
- Is there a standard function to check for null, undefined, or blank variables in JavaScript?
- How to force JavaScript to deep copy a string?
- How to go to a URL using jQuery?
- Uncaught ReferenceError: ga is not defined
- jQuery .animate() not working
- how to add inside a text box?
- is it posible to add anime.js in WordPress
- What type of template are WP media-modal’s templates?
- Eliminate render blocking javascript
- is_front_page() not working
- The value of attribute [ data-type ] must be in double quotes – custom html widget error
- Gutenberg RichText
- Add tinymce dynamically via Javascript
- Sending custom data with Media Frame Model
- Make TinyMCE checkbox that returns a value instead of true/false
- Unwanted line break before
- Adding JavaScript to a WordPress website
- wp-env mysqlcheck error:1130
- How to disable inline css styles generated by Gutenberg editor?
- Multiple Conditional Controllers
- Adding javascript trigger to user role selection on the user-edit page
- Vue and wordpress.Bad Request ajax request
- How to add if lt IE9 conditional scripts to functions.php
- Looping over wordpress meta to create “ ‘s?
- How to include a JSON file on my page?
- Adding inline JavaScript after wp_enqueue_scripts
- How to add “on change” to a text input in contact form7?
- Update media library attachments
- JavaScript Libraries in WordPress
- How to use WP switchEditors.switchto(this) JS function in your own script?
- Landing function through URL
- Escaping quotes while enqueuing scripts
- Create new product with woocommerce REST API with javascript (clientside)?
- Combining results from WP-API using AngularJS
- dropdown does not work [closed]
- Anyway to disable the auto excerpt creation?
- How do I cycle a JS function in WordPress? [closed]
- Why is this script not working?