-2

Trial 1: Within the same HTML file

Head:

<script>
    function backSpace() {
        var bsp = document.getElementById("ns").value;
        document.getElementById("ns").value=bsp.substring(0,bsp.length -1);
    }
</script>

Body:

<span class="num" onclick="backSpace()"><i class="fas fa-backspace">Backspace</i></span>

Trial 2
Is there a way to use "--" of the existing value and just backspace without using functions?

Sven Eberth
  • 3,057
  • 12
  • 24
  • 29
Zubair
  • 1
  • 1

1 Answers1

0

Use event.which to trigger backspace button:

<script>
$(document).ready(function(){
  $("input").keydown(function(event){
    if (event.which === 8) { // 8 is the code for backspace
        console.log('Backspace is pressed');
        var bsp = document.getElementById("ns").value;
        // do the rest of the code here..
       }
  });
});
</script>