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

186
Views
No se puede actualizar el valor del área de texto con texto formateado

Estoy tratando de escribir una función JS que tome un bloque de texto pegado dentro del área de texto, elimine los saltos de línea pero mantenga los saltos de párrafo y actualice el texto dentro de ese área de texto antes de enviar un formulario.

He intentado hacerlo de esta manera:

 <textarea name="sum" id="sum" onpaste="frmt()"></textarea>

JS:

 function frmt() { const tar = document.getElementById("sum"); const reg = /[\r\n](?![\r\n])/g; const str = tar.value; tar.innerHTML = str.replace(reg, ""); }

¿Qué me estoy perdiendo?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

<textarea name="sum" id="sum"></textarea> <script> const sum = document.getElementById('sum'); sum.addEventListener('paste', () => setTimeout( () => (sum.value = sum.value.replace(/[\r\n](?![\r\n])/g, '')), 0 ) ); </script>

https://developer.mozilla.org/en-US/docs/Web/API/Element/paste_event

about 4 years ago · Juan Pablo Isaza Report

0

<textarea> no es compatible con .innerHTML , por lo que debe establecer valores a través .value y puede usar el evento oninput .

Este evento ocurre cuando se cambia el valor de un elemento <input> o <textarea> .

Enlaces Útiles:
https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/oninput https://www.w3schools.com/jsref/event_oninput.asp

 function frmt(id){ const tar = document.getElementById(id); const reg = /[\r\n](?![\r\n])/g; const str = tar.value; tar.value = str.replace(reg, "") }
 textarea{ width: 95%; height: 160px; }
 <textarea name="sum" id="sum" oninput="frmt('sum')"></textarea>

about 4 years ago · Juan Pablo Isaza Report
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!