cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
riteshratna
Nintex Newbie

Read and Clear the last line of Multiline Textbox, using JavaScript

Jump to solution

I have a Multiline Textbox with with multiple lines of data in it.

Using Javascript, I want read just the last line in a variable and then remove/delete the last line from the control.

On button Click I am able to write the data to the Control.

var OldData = NWF$('#'+ fldMultiLine).val();
var NewData = 'This could be any data';
NWF$('#'+ fldMultiLine).val(OldData + (OldData.length ? '\r\n' : '') + NewData);

On button Click I am also able to delete all the data from the control

NWF$('#'+ fldMultiLine).val('');

What I need is to, On button click just -

1) Read the last line into a variable,

2) Then, delete only the last line from the control.

I would appreciate any help extended.

Thanks

Labels: (1)
0 Kudos
Reply
4 Replies
sojanm
Nintex Newbie

Re: Read and Clear the last line of Multiline Textbox, using JavaScript

Jump to solution

When you click on the remove button, use javascript to read the data into an array. Remove the last line and write it back.

0 Kudos
Reply
riteshratna
Nintex Newbie

Re: Read and Clear the last line of Multiline Textbox, using JavaScript

Jump to solution

Thanks Sojan.

This I am sure your logic would work.

However, I was able to do it without using the array. I am copyimg the code, I used, here.

Though, let me acknowledge, I got the hint from your suggestion.

Hence, thanks all the same, I appreciate your time and effort. 

Reply
riteshratna
Nintex Newbie

Re: Read and Clear the last line of Multiline Textbox, using JavaScript

Jump to solution

I was able to do the trick using the following code -

function RemoveLastLine()
{
     var OldData = NWF$('#'+ fldMultiLine).val();   

     if(OldData.lastIndexOf("\n")>0)
    {
          var TruncatedData = OldData.substring(0, OldData.lastIndexOf("\n"));
          NWF$('#'+ fldMultiLine).val('');
          NWF$('#'+ fldMultiLine).val(TruncatedData);
      }
     else
     {
          NWF$('#'+ fldMultiLine).val('');
      }
 }

Reply
sojanm
Nintex Newbie

Re: Read and Clear the last line of Multiline Textbox, using JavaScript

Jump to solution

You can also try RegEx to remove the last line.

0 Kudos
Reply