How to know which character(s) is(are) get deleted on backspace or delete button click when editing text in textarea.
I want to get character get deleted on backspace or delete button click to detect if deleted character is new line character.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well you can do 2 things.
You could either store the current value and compare it to the new value.
Or you can try to catch the event before it really does what it has to do.
I found this prevent backspace function here
check if its any use of you.
You can use the SelectionStart function to find out what the position of your cursor is.
By checking the keycode you can determine if the backspace or delete button was pressed.
Delete will mean: position +1 is the character being deleted.
Backspace will mean: position -1 is the character being deleted.
Because you are preventing backspace and/or delete to trigger their original event you have all the time to find those things out.
Once you know all the information you needed to know you can manually remove the character from the string and update the text in the textarea.
Not sure if its the best way but it seems like something that could work like this.
Hope this helped you in any way.