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…
JavaScript
x
31
31
1
$(document).on('ready', function() {
2
$('.quoteMsg').click(function() {
3
var txt = $(this).closest('.replyBox').find('.replyMsg').html().trim();
4
var txtau = $(this).closest('.replyBox').find('.replyMsgau').text().trim();
5
txt = txt.replace(/(?:rn|r|n)/g, ' ');
6
txt = txt.replace(/<p class="c0">/gi, '');
7
txt = txt.replace(/</p>/gi, '');
8
txt = txt.replace(/</g, "<");
9
txt = txt.replace(/>/g, ">");
10
txt = txt.replace(/&/g, "&");
11
txt = txt.replace(/"/g, '"');
12
txt = txt.replace(/'/g, "'");
13
var txtq = txt; //it doesn't work to pass the whole value to the txtq variable
14
//txtq = txt; //also not working
15
txtq = txt;
16
txtq = txt.replace(/<blockquote>/gi, '');
17
txtq = txt.replace(/</blockquote>/gi, '[hr][i]' + txtau + '[/i]: ');
18
19
var txte = txt; //it doesn't work to pass the whole value to the txte variable
20
//txte = txt; //also not working
21
txte = txt.replace(/<blockquote>/gi, '[quote]');
22
txte = txt.replace(/</blockquote>/gi, '[/quote]n');
23
txte = txt.replace(/<blockquote>/gi, '');
24
25
$("textarea[name='tresckomentapisz']").val('[quote]' + txtq + '[/quote]n' + txtau + ', ');
26
$("textarea[name='editkomtxt']").val(txte);
27
28
29
});
30
});
31
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>|
Advertisement
Answer
For txtq
and txte
, you are modifiying txt
var.
Insted of:
JavaScript
1
2
1
txtq = txt.replace(/<blockquote>/gi, '');
2
try:
JavaScript
1
2
1
txtq = txtq.replace(/<blockquote>/gi, '');
2