Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

315
Views
Get selection offset of string in textarea containing multibyte characters

It seems that the selectionStart and selectionEnd properties of a textarea element in Javascript are not multi-byte safe, returning the wrong values for the selection offset when multibyte characters are present:

https://jsfiddle.net/skeets23/wdnrj89k/16/

Is there any way to work around this and get the correct selection offsets?

My usage case is: I want to allow the user to save a section of "highlighted" text in a given paragraph. So they can select text and press "save", and it sends the "start" and "end" value of their selection to the back end (which is already multi-byte compatible (PHP, so mb_* functions))

I tried disabling multi-byte compatibility on the back end in hopes that at least the front end and the back end would treat multi-bite strings in the same way, but that wasn't the case... it gave me garbled text :P

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!