How do I insert new line characters to a string when entered in an input box [duplicate]
This question already has an answer here:
HTML newline using fromCharCode is not working
2 answers
html label inserting newline
3 answers
I'm trying to replace substrings. The substitution is entered in an input box. The thing is that I am unable to insert n via the input box.
So this does not work
var val = document.getElementById('val').innerHTML;
var replacement = document.getElementById('replaceWith').value
val.innerHTML = val.innerHTML.replace(reg, replacement + '$&');
But this does work
var val = document.getElementById('val').innerHTML;
var replacement = document.getElementById('replaceWith').value
val.innerHTML = val.innerHTML.replace(reg, "n" + '$&');
Is there a way to accomplish this?
javascript regex
marked as duplicate by T.J. Crowder
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 28 '18 at 15:02
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
HTML newline using fromCharCode is not working
2 answers
html label inserting newline
3 answers
I'm trying to replace substrings. The substitution is entered in an input box. The thing is that I am unable to insert n via the input box.
So this does not work
var val = document.getElementById('val').innerHTML;
var replacement = document.getElementById('replaceWith').value
val.innerHTML = val.innerHTML.replace(reg, replacement + '$&');
But this does work
var val = document.getElementById('val').innerHTML;
var replacement = document.getElementById('replaceWith').value
val.innerHTML = val.innerHTML.replace(reg, "n" + '$&');
Is there a way to accomplish this?
javascript regex
marked as duplicate by T.J. Crowder
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 28 '18 at 15:02
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
You need to define a kind of a special newline representation. If you are OK withn, just usereplacement.replace(/\n/g, "n")
– Wiktor Stribiżew
Nov 28 '18 at 15:02
input type="text"is for single line text.textareais what you want.
– Daniel A. White
Nov 28 '18 at 15:04
If the linked questions don't solve your problem, your question may not be clear. If that's the case, please update your question with a Minimal, Complete, and Verifiable example demonstrating the problem, ideally a runnable one using Stack Snippets (the[<>]toolbar button; here's how to do one).
– T.J. Crowder
Nov 28 '18 at 15:05
@Wiktor That almost worked but. It does insert a new line but also quotation marks
– MK01111000
Nov 28 '18 at 15:10
Oh, you must have pasted my code in a wrong way.
– Wiktor Stribiżew
Nov 28 '18 at 15:11
add a comment |
This question already has an answer here:
HTML newline using fromCharCode is not working
2 answers
html label inserting newline
3 answers
I'm trying to replace substrings. The substitution is entered in an input box. The thing is that I am unable to insert n via the input box.
So this does not work
var val = document.getElementById('val').innerHTML;
var replacement = document.getElementById('replaceWith').value
val.innerHTML = val.innerHTML.replace(reg, replacement + '$&');
But this does work
var val = document.getElementById('val').innerHTML;
var replacement = document.getElementById('replaceWith').value
val.innerHTML = val.innerHTML.replace(reg, "n" + '$&');
Is there a way to accomplish this?
javascript regex
This question already has an answer here:
HTML newline using fromCharCode is not working
2 answers
html label inserting newline
3 answers
I'm trying to replace substrings. The substitution is entered in an input box. The thing is that I am unable to insert n via the input box.
So this does not work
var val = document.getElementById('val').innerHTML;
var replacement = document.getElementById('replaceWith').value
val.innerHTML = val.innerHTML.replace(reg, replacement + '$&');
But this does work
var val = document.getElementById('val').innerHTML;
var replacement = document.getElementById('replaceWith').value
val.innerHTML = val.innerHTML.replace(reg, "n" + '$&');
Is there a way to accomplish this?
This question already has an answer here:
HTML newline using fromCharCode is not working
2 answers
html label inserting newline
3 answers
javascript regex
javascript regex
asked Nov 28 '18 at 14:59
MK01111000MK01111000
896
896
marked as duplicate by T.J. Crowder
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 28 '18 at 15:02
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by T.J. Crowder
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 28 '18 at 15:02
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
You need to define a kind of a special newline representation. If you are OK withn, just usereplacement.replace(/\n/g, "n")
– Wiktor Stribiżew
Nov 28 '18 at 15:02
input type="text"is for single line text.textareais what you want.
– Daniel A. White
Nov 28 '18 at 15:04
If the linked questions don't solve your problem, your question may not be clear. If that's the case, please update your question with a Minimal, Complete, and Verifiable example demonstrating the problem, ideally a runnable one using Stack Snippets (the[<>]toolbar button; here's how to do one).
– T.J. Crowder
Nov 28 '18 at 15:05
@Wiktor That almost worked but. It does insert a new line but also quotation marks
– MK01111000
Nov 28 '18 at 15:10
Oh, you must have pasted my code in a wrong way.
– Wiktor Stribiżew
Nov 28 '18 at 15:11
add a comment |
You need to define a kind of a special newline representation. If you are OK withn, just usereplacement.replace(/\n/g, "n")
– Wiktor Stribiżew
Nov 28 '18 at 15:02
input type="text"is for single line text.textareais what you want.
– Daniel A. White
Nov 28 '18 at 15:04
If the linked questions don't solve your problem, your question may not be clear. If that's the case, please update your question with a Minimal, Complete, and Verifiable example demonstrating the problem, ideally a runnable one using Stack Snippets (the[<>]toolbar button; here's how to do one).
– T.J. Crowder
Nov 28 '18 at 15:05
@Wiktor That almost worked but. It does insert a new line but also quotation marks
– MK01111000
Nov 28 '18 at 15:10
Oh, you must have pasted my code in a wrong way.
– Wiktor Stribiżew
Nov 28 '18 at 15:11
You need to define a kind of a special newline representation. If you are OK with
n, just use replacement.replace(/\n/g, "n")– Wiktor Stribiżew
Nov 28 '18 at 15:02
You need to define a kind of a special newline representation. If you are OK with
n, just use replacement.replace(/\n/g, "n")– Wiktor Stribiżew
Nov 28 '18 at 15:02
input type="text" is for single line text. textarea is what you want.– Daniel A. White
Nov 28 '18 at 15:04
input type="text" is for single line text. textarea is what you want.– Daniel A. White
Nov 28 '18 at 15:04
If the linked questions don't solve your problem, your question may not be clear. If that's the case, please update your question with a Minimal, Complete, and Verifiable example demonstrating the problem, ideally a runnable one using Stack Snippets (the
[<>] toolbar button; here's how to do one).– T.J. Crowder
Nov 28 '18 at 15:05
If the linked questions don't solve your problem, your question may not be clear. If that's the case, please update your question with a Minimal, Complete, and Verifiable example demonstrating the problem, ideally a runnable one using Stack Snippets (the
[<>] toolbar button; here's how to do one).– T.J. Crowder
Nov 28 '18 at 15:05
@Wiktor That almost worked but. It does insert a new line but also quotation marks
– MK01111000
Nov 28 '18 at 15:10
@Wiktor That almost worked but. It does insert a new line but also quotation marks
– MK01111000
Nov 28 '18 at 15:10
Oh, you must have pasted my code in a wrong way.
– Wiktor Stribiżew
Nov 28 '18 at 15:11
Oh, you must have pasted my code in a wrong way.
– Wiktor Stribiżew
Nov 28 '18 at 15:11
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to define a kind of a special newline representation. If you are OK with
n, just usereplacement.replace(/\n/g, "n")– Wiktor Stribiżew
Nov 28 '18 at 15:02
input type="text"is for single line text.textareais what you want.– Daniel A. White
Nov 28 '18 at 15:04
If the linked questions don't solve your problem, your question may not be clear. If that's the case, please update your question with a Minimal, Complete, and Verifiable example demonstrating the problem, ideally a runnable one using Stack Snippets (the
[<>]toolbar button; here's how to do one).– T.J. Crowder
Nov 28 '18 at 15:05
@Wiktor That almost worked but. It does insert a new line but also quotation marks
– MK01111000
Nov 28 '18 at 15:10
Oh, you must have pasted my code in a wrong way.
– Wiktor Stribiżew
Nov 28 '18 at 15:11