SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot j3ph's Avatar
    Join Date
    Jan 2006
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile 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:

    Code:
    $("#backspace").click(function() {
        $("#cell").value($("#cell").substring(0, $("#cell").length() - 1);
    });
    It doesn't work Can someone shed some light on what I'm doing wrong.

    Thanks!

  2. #2
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    To get or set values of text fields with jQuery you should use .val().
    Untested, but something like the following should work:

    Code:
    $("#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.

  3. #3
    SitePoint Zealot j3ph's Avatar
    Join Date
    Jan 2006
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That worked perfectly. Thank you very much!


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •