Answers for "disable submit button if input is empty"

0

disable submit button if input is empty

document.getElementById('submitID').disabled = true; //Disable at first

//Listen for keyup event (after we hit a key)
//-----------------------------------------------------------
//NOTE: We can also use the change event, but the submit button
//      won't update until we finish typing the whole thing
//-----------------------------------------------------------
document.getElementById('myInputFieldID').addEventListener('keyup', e => {
  //Check for the input's value
  if (e.target.value == "") {
    document.getElementById('submitID').disabled = true;
  }
  else {
    document.getElementById('submitID').disabled = false;
  }
});

//Happy coding :)
Posted by: Guest on October-11-2021

Code answers related to "disable submit button if input is empty"

Code answers related to "Javascript"

Browse Popular Code Answers by Language