Pravin Kumar Raja Posted October 30, 2019 Share Posted October 30, 2019 I had 2 INPUT boxes and one BUTTON. I want to take the control back to the current INPUT after BUTTON is clicked. That part is working fine with the HTML file shown below: <!DOCTYPE html> <html> <head> <script> var last; function Focus(input) { last = input; } function Blur(input) { } function Click(button) { if (typeof last != "undefined") last.focus(); } </script> </head> <body> <input id="I1" onfocus="Focus(this)" onblur="Blur(this)"> </input> <input id="I2" onfocus="Focus(this)" onblur="Blur(this)"> </input> <button id="B" onclick="Click(this)"> Click </button> <script> </script> </body> </html> But I wanted to code onblur function Blur to incorporate check whether the input is exited with a blank string and to return control to the blank INPUT field after displaying an alert to that effect. This displays the alert box continuously. Can you suggest how this can be avoided. Here is my code: function Focus(input) { if (typeof last != "undefined") if (last.value.length == 0) alert("Blank!"); last = input; } Link to comment Share on other sites More sharing options...
Funce Posted November 11, 2019 Share Posted November 11, 2019 Well that would be because your alert code is inside your Focus function and not your Blur function. So the alert is executing (after you've focused), then when you close the alert it refocuses which causes the alert again. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now