Home > Blockchain >  value of text.replace() to another variable
value of text.replace() to another variable

Time:12-27

I have a code to clear and paste text after clicking a button. This text is pasted into two different textareas and therefore my code has to clean up the intercepted content a bit differently. The problem is that it doesn't work to pass the content to another variable...

$(document).on('ready', function() {
  $('.quoteMsg').click(function() {
    var txt = $(this).closest('.replyBox').find('.replyMsg').html().trim();
    var txtau = $(this).closest('.replyBox').find('.replyMsgau').text().trim();
    txt = txt.replace(/(?:\r\n|\r|\n)/g, ' ');
    txt = txt.replace(/<p >/gi, '');
    txt = txt.replace(/<\/p>/gi, '');
    txt = txt.replace(/&lt;/g, "<");
    txt = txt.replace(/&gt;/g, ">");
    txt = txt.replace(/&amp;/g, "&");
    txt = txt.replace(/&quot;/g, '"');
    txt = txt.replace(/&#039;/g, "'");
var txtq = txt; //it doesn't work to pass the whole value to the txtq variable
//txtq = txt; //also not working
    txtq = txt;
    txtq = txt.replace(/<blockquote>/gi, '');
    txtq = txt.replace(/<\/blockquote>/gi, '[hr][i]'   txtau   '[/i]: '); 
    
var txte = txt; //it doesn't work to pass the whole value to the txte variable
//txte = txt; //also not working
    txte = txt.replace(/<blockquote>/gi, '[quote]');
    txte = txt.replace(/<\/blockquote>/gi, '[/quote]\n');
    txte = txt.replace(/<blockquote>/gi, '');

    $("textarea[name='tresckomentapisz']").val('[quote]'   txtq   '[/quote]\n'   txtau   ', ');
    $("textarea[name='editkomtxt']").val(txte);


  });
});

I want txtq and txte to format the value differently for <blockquote>, but data transfer from txt doesn't work - why?

I need this efect for <quote>: console.log(txtq '|' txte '|' txt);//[hr][i]etc[/i] | [quote]\n

but is working like that: console.log(txtq '|' txte '|' txt);//<blockquote>|<blockquote>|

CodePudding user response:

For txtq and txte, you are modifiying txt var.

Insted of:

txtq = txt.replace(/<blockquote>/gi, '');

try:

txtq = txtq.replace(/<blockquote>/gi, '');
  • Related