Creating a Backspace Key

I’m trying to create a button that when pressed will remove the last character entered in a text field called “cell” using jQuery.

Here is what I have:


$("#backspace").click(function() {
    $("#cell").value($("#cell").substring(0, $("#cell").length() - 1);
});

It doesn’t work :slight_smile: Can someone shed some light on what I’m doing wrong.

Thanks!

To get or set values of text fields with jQuery you should use .val().
Untested, but something like the following should work:


$("#backspace").click(function() {
    var el = $("#cell");
    var the_value = el.val();
    the_value = the_value.substring(0, the_value.length - 1);
    el.val(the_value);
});

I’ve split the code into several steps to show what’s going on.

That worked perfectly. Thank you very much!