Home > Mobile >  How to check if an element has been unselected using JS?
How to check if an element has been unselected using JS?

Time:08-03

I'm trying to check if an element has been unselected in a form; So I can check if the input is valid, but i'm stuck at the selected part; I've tried to add onclick() functions but as the div containing my form is selected too when I click on an input field, it's not working. Any ideas ?

this is what I have for a form click :

document.getElementById("contactForm").onclick = function ()
{
  if (messageClicked==1){
    console.log(document.getElementById("formMessage").value);
  }
  
}

and for an input :

document.getElementById("formMessage").onclick = function ()
{
  messageClicked=1;
}

CodePudding user response:

The answer is indeed the blur event ! Thanks user19642323 !

  • Related