Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

317
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda