Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Detect backspace pressed eventlistener

document.addEventListener("keydown", function(event) 
{
  if (event.key == "c") 
  {
    console.log("C Pressed");
    document.getElementById("btnConvert").click();
  }

  var convertButton = document.getElementById("btnConvert");
  if (event.key == "Backspace") 
  {
    console.log("Backspace Pressed");
    var textboxContent = document.getElementById("txtFahrenheit").value;
    if (textboxContent.value == "" || textboxContent.value == "-")
    {
      convertButton.disabled = true;
    }
  }
})

/*HTML:
<button id="btnConvert">Convert</button>
<input id="txtFahrenheit" type="text" autofocus />
*/
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Detect #backspace #pressed #eventlistener
ADD COMMENT
Topic
Name
3+8 =