Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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 :)
 
PREVIOUS NEXT
Tagged: #disable #submit #button #input #empty
ADD COMMENT
Topic
Name
5+6 =