Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete last character from input

Tags:

How could I delete the last character from an input in JQuery? For example, onclick of something, it deletes the last character (a comma in my case) from an input field.

like image 470
sir_thursday Avatar asked Jul 31 '11 18:07

sir_thursday


People also ask

How do I remove the last character of a string?

The easiest way is to use the built-in substring() method of the String class. In order to remove the last character of a given String, we have to use two parameters: 0 as the starting index, and the index of the penultimate character.

How to take the last character off a string in JavaScript?

To get the last character of a string, call the charAt() method on the string, passing it the last index as a parameter. For example, str. charAt(str. length - 1) returns a new string containing the last character of the string.


1 Answers

$(input).val(     function(index, value){         return value.substr(0, value.length - 1); }) 
like image 165
RiaD Avatar answered Oct 01 '22 09:10

RiaD