1

I'm implementing a set of buttons which when pressed type alphanumeric characters in a textbox.

How can I implement backspace button so that whenever it is pressed, the last character in the textbox is erased from the textbox?

2 Answers 2

5

Try the below (Javascript)code on the press of a button...

var mytxtbx=document.getElementById("IdOfTextBox");
mytxtbx.value=mytxtbx.value.substring(0,(mytxtbx.value.length-1))

Try the below (JQuery)code on the press of a button...

$("#IdOfTextBox").val($("#IdOfTextBox").val().substring(0,($("#IdOfTextBox").val().length-1)))
Sign up to request clarification or add additional context in comments.

Comments

0

Though already answered, you might cleanup his code a bit and "cache" some variables:

function RemoveLastChar(){
    var field = $("#fieldID");
    var oldValue = field.val();
    field.val(oldValue.substring(0, oldValue.length - 1));
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.