Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
23
rated 0 times [  24] [ 1]  / answers: 1 / hits: 57271  / 13 Years ago, mon, june 13, 2011, 12:00:00

I have a textarea where I insert n when user presses enter. Code from this textarea is sent to a WCF service via jQuery.ajax(). I cannot save n in DB as it won't show in other applications consuming the service.



How can i replace n with <br /> tag?



solution



Well many of you tried and some got right with Javascript Regex with /g (global modifier).
At the end i had n inserted twice, i don't know why, my only guess is that jQuery on keypress event created double n which i debug.



$('#input').keypress(function (event) {
if (event.which == '13') {
inputText = $('#input').val() + 'n';
$('#input').val(inputText);
}
});

More From » jquery

 Answers
148

Replace with global scope



$('#input').val().replace(/n/g, <br />)


or



$('#input').val().replace(n, <br />, g)

[#91743] Friday, June 10, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
debra

Total Points: 583
Total Questions: 111
Total Answers: 111

Location: Reunion
Member since Mon, Dec 28, 2020
4 Years ago
;