Remove first line from Textarea

user3806255

I have a tool that removes the blank lines from a confirmation (text) but for some reason there is a top line that is not being read as blank line and does not get deleted.

Currently my tool allows a person to paste text into the textarea then when "remove spaces & copy" button is clicked blank lines are removed and text is copied to the clipboard.

I want to keep the same function but somehow delete the first line either when text is entered into the textarea or when "remove spaces & copy" button is clicked.

 <script>
 function copyToClipboard(element) {
  var text = $(element).clone().find('br').prepend('\r\n').end().text()
  element = $('<textarea>').appendTo('body').val(text).select()
  document.execCommand('copy')
  element.remove()
  }
  </script>

<textarea name="mas" rows="100" rows="50" contenteditable="true" id="p20" class="content" onchange="this.value=this.value.replace(/[\n\r](?!\w)/gi,'');" style="height: 500px; width:800px;" type="text" data-bind="value: myValue, hasFocus: cleared"></textarea>



<!----------- BUTTONS ------------>
<div class="fixed">
<button onclick="copyToClipboard('#p20')" class="templateBtn">Remove Spaces & Copy</button>
<input type="button" data-bind="click: clearValue" value="clear" class="templateBtn" />
<script type="text/javascript">
    var viewModel = {
   myValue: ko.observable(''),
   cleared: ko.observable(false),
   clearValue: function() {       
   this.myValue('');   
   this.cleared(true);
    }
  };

  ko.applyBindings(viewModel);
   </script>

  <!----------- END.BUTTONS ------------>

 <div class="mas" id="hide" ></div>

 <pre contenteditable="true" id="p20" class="templateText">

 </div></div>
Sébastien

Here is a quick fix you could use, perform a trim() on the replaced text:

<textarea name="mas" rows="100" rows="50" contenteditable="true"
id="p20" class="content"
onchange="this.value=(this.value.replace(/[\n\r](?!\w)/gi,'')).trim();"
style="height: 500px; width:800px;" type="text"
data-bind="value: myValue, hasFocus: cleared"></textarea>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to remove first character in each line of textarea

JavaScript - How to remove new line from textarea if no text exists before?

Remove every even line from textarea using jQuery

Java Remove First Line from byte[]

Read the first line in a stream and remove it from the stream

Remove first empty line from a file

sed remove from php first line

Delete first Line of a JavaFx Textarea

need to remove first line from a string and then first two word in scala

Trying to remove first few characters from each line but not able to remove ./

VI replace or remove the first character from line to line

Remove scrollbars from textarea

removing line by line from textarea

Is the caret on the first line of the textarea? On the last line?

remove first line in bash

Systematically remove first line

StringJoiner remove delimeter from first position for every line

remove the first 15 characters from every other line in a file

How to remove first line from a String containing XML?

How to remove the first dot from every line but only if it exists

Pyspark dataframe: load from csv and then remove the first line

Remove extra header lines from file, except for the first line

I only want to remove quotes from the first line

Read and remove first (or last) line from txt file without copying

Batch: Remove linefeed from variable containing first line of file

How to remove first line text from text-box?

Remove first character in line from text only if it matches defined character

REMOVE FIRST LINE from TEXT file AFTER running a script in POWERSHELL

Remove image from div and textarea

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  3. 3

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  4. 4

    pump.io port in URL

  5. 5

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    Do Idle Snowflake Connections Use Cloud Services Credits?

  9. 9

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  10. 10

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  11. 11

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  12. 12

    Generate random UUIDv4 with Elm

  13. 13

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  14. 14

    Is it possible to Redo commits removed by GitHub Desktop's Undo on a Mac?

  15. 15

    flutter: dropdown item programmatically unselect problem

  16. 16

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  17. 17

    EXCEL: Find sum of values in one column with criteria from other column

  18. 18

    Pandas - check if dataframe has negative value in any column

  19. 19

    How to use merge windows unallocated space into Ubuntu using GParted?

  20. 20

    Make a B+ Tree concurrent thread safe

  21. 21

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

HotTag

Archive