mardi 6 novembre 2018

Enable and disable button by if

I have a problem with my js code. I have managed to disable the submit button, if there is no input value, but now I want to enable it again when a value is present. Thank you very much

// submit message
submitButton.addEventListener("click", (e) =>{
  if(userMessage.value = " ") {
    submitButton.setAttribute("disabled", true);
    alert("fill field");

  } if(userMessage.value != " ") {
    submitButton.setAttribute("disabled", false);
   alert("send");
  }
  // prevent default
  e.preventDefault();
})

Aucun commentaire:

Enregistrer un commentaire