0

How do I delete/remove input values on backspace using javascript or jquery? I entered several email ids in a textbox by separating them with comma, tab etc. On backspace key I want to delete the input values one by one.

Please give any function to implement this functionality.


Here is my front end code:

<div class="textarea-wrapper topspacing-subsection leftspacing-subsection ">
    <div class="textarea wordcontainer" style="display:inline-block;width:690px;" onclick="javascript:document.getElementById('txtSendFromType').focus();">
        <%--width 372 px removed from  txtSendFromType--%>
            <asp:TextBox ID="txtSendFromType" runat="server" CssClass="word" BorderStyle="None" AutoCompleteType="Disabled" onkeypress="this.style.width = ((this.value.length + 1) * 8) + 'px';"></asp:TextBox>
    </div>
</div>
Ben Rhys-Lewis
  • 3,118
  • 8
  • 34
  • 45
Bharat Koshti
  • 81
  • 1
  • 4
  • 10

1 Answers1

1

Use this, hope it helps you:

var input = document.getElementById('txtSendFromType');
  input.onkeydown = function() {
  var key = event.keyCode || event.charCode;
  if( key == 8 || key == 46 )
    return false;   
};
Ben Rhys-Lewis
  • 3,118
  • 8
  • 34
  • 45
Anuj Kumar
  • 160
  • 1
  • 2
  • 11
  • i tried this code but not working for me. but then also thanks for your help. – Bharat Koshti Jun 23 '16 at 06:35
  • $(document).ready(function () { $('body').on('keyup', 'input.word', function (e) { if ($('.word').val().length === this.size) { var inputs = $('input.word'); inputs.remove(); } if (e.keyCode == 8 || e.keyCode == 46) { var inputs = $('input.word'); inputs.remove(); return false; } }); }); – Bharat Koshti Jun 23 '16 at 09:54
  • i used this but it delete or remove current input value but if i click backspace twice 0r thrice it goes back – Bharat Koshti Jun 23 '16 at 09:54