I have this:
data.data.message = 'User created';
app.successMsg = data.data.message + '...Redirecting';
And I want to add a line before the ...Redirecting. I've tried \n, \r, both together but it's not working. I've also read some articles here but they all tell them to use the \n and \r but it's not working for me. I'm just learning so be patient please.
---------------------------------------------------------------EDIT--------------------------------------------------------------
When I use '<br />.... Redirecting' this happens:
Thanks!
You may use <br/> tag to get a new line.
apart of that, you may use any block element(e.g. div) to show it to other line. it actually puts it in another element and block element is always rendered in new line so data goes to next line. you can then apply css to it as well.
If you run it in a browser, then my guess is it's rendered as HTML. HTML ignores newlines, and puts everything on the same line. So you could either put the above text between <pre> brackets, or echo our <br /> where you want a new line. Hope that helps.
Related
I am creating a form for medical prescription. Here one of the textarea field name is new prescription. Doctor will insert value here like
1. medicine-l
1+1+1
2. medicine-2
1+0+1
But while I print out the prescription this new prescription field shows it's value like
1.medicine-1 1+1+1 2.medicine-2 1+0+1
But I want to printout the value of new prescription just like how doctor inserted.
How can I do it? Anybody Help Please ?
The line breaks are actually preserved untill you print the text out. HTML doesn't doesn't detect the line breaks in the text.
Try this for JS:
textAreaText.replace(/(?:\r\n|\r|\n)/g, '<br>');
How do I replace all line breaks in a string with <br /> tags?
Try this for PHP :
http://php.net/manual/en/function.nl2br.php
You should be able to do this using the CSS property white-space.
Example:
.textarea-class {
white-space: pre-wrap;
}
Consult the MDN docs for a very nice overview if the various options, but it seems like you want either pre (just as it is), pre-wrap (maintains spacing and line breaks, but wraps), or even pre-line (maintains line breaks but not spacing, and wraps).
You’ll want to put this in your print stylesheet.
So I'm trying to add text inside a variable and the variable together. But every time I add new text I want it to be added on another line. So when it's spread on multiple lines instead of it being just on one line.
Here is the code I have for it so far. How do I put the old sResults on the lower lines?
sResults = ("You Are The Boss" + sResults)
I've tried using <p> in it but I don't think I'm implementing it right. I tried using \n like in AS3 but that's not working and also <tr> like for tables but I'm still pretty new to HTML and i have no idea.
if you are using javascript then try this way :
sResults = ("You Are The Boss" + sResults)
sResult=sResult+"<br>";
To force a new line in HTML then you need to use the br tag.
Is it possible to style the contents of a textarea with CSS? I need to at the very least, insert more space after line breaks.
I want to basically have a new paragraph of text start within the textarea after every carriage return or line break.
You can't style the content of a textarea. All you can do is insert more whitespace manually.
One approach is to replace single carriage returns with double ones
This can be done with either Javascript or PHP...
JS: str.replace("\r\n", "<br />");
http://www.w3schools.com/jsref/jsref_replace.asp
PHP: str_replace("\r\n", "<br />", "whatyouaresearching", "number of replacements you want to make")
http://php.net/manual/en/function.str-replace.php
These are "String Replace" functions. So essentially what we are doing is searching a given string for a certain value and replacing it with another value.
Edit: Looks like I may have incorrectly assumed that the text area would interpret correctly. OP, have you tried yet? If that doesn't work, then try using the HTML Entity Code as the replace value:
http://www.w3schools.com/tags/ref_ascii.asp
This should not be that hard but I can't seem to find information on it. How do you get line breaks to appear inside a text area when you are echoing it from the server? In other words what is <some code> in line below?
<text area>first line <some code> second line <some code> third line</text area>
I know how to write out <some code>. I just need to know what it should be. I have tried \n, \r\n, '\n', "\n", \N and variations but cannot get the line breaks to display.
Note: This is not about displaying in HTML so <br> is not what I want. This is not about getting it to display if you are typing it yourself where you can type a carriage return, i.e. :
<textarea>first line
second line </textarea>
When you are outputting from server you cannot use keyboard. This is what code to accomplish above.
Thanks for any suggestions
This is a super old question, but I ran into the same issue ajaxing content into a text area.
Thanks to this answer I used the html code for a new line,
and that worked for me. So basically:
<textarea> Here's my returned text
And it gets two lines </textarea>
which (at least for me) comes out as
Here's my returned text
And it gets two lines
try this
<'p'>firstline<'/p'>
<'p'>secondline<'/p'>
remove comma from p and /p
for display \n in html you should use nl2br() php function .
otherwise you should using "\n" (not "/n") for break the line inside your text ;
You should try \r\n instead of /r/n.
You need to use "\r\n" (with double quotes) when echoing it out from PHP.
How can i add a line break to the text area in a html page?
i use VB.net for server side coding.
If it's not vb you can use
(ascii codes for cr,lf)
Add a linefeed ("\n") to the output:
<textarea>Hello
Bybye</textarea>
Will have a newline in it.
You could use \r\n, or System.Environment.NewLine.
If you're inserting text from a database or such (which one usually do), convert all "<br />"'s to &vbCrLf. Works great for me :)
In a text area, as in the form input, then just a normal line break will work:
<textarea>
This is a text area
line breaks are automatic
</textarea>
If you're talking about normal text on the page, the <br /> (or just <br> if using plain 'ole HTML4) is a line break.
However, I'd say that you often don't actually want a line break. Usually, your text is seperated into paragraphs:
<p>
This is some text
</p>
<p>
This is some more
</p>
Which is much better because it gives a clue as to how your text is structured to machines that read it. Machines that read it include screen readers for the partially sighted or blind, seperating text into paragraphs gives it a chance of being presented correctly to these users.
I believe this will work:
TextArea.Text = "Line 1" & vbCrLf & "Line 2"
System.Environment.NewLine could be used in place of vbCrLf if you wanted to be a little less VB6 about it.
Escape sequences like "\n" work fine ! even with text area! I passed a java string with the "\n" to a html textarea and it worked fine as it works on consoles for java!
Here is my method made with pure PHP and CSS :
/** PHP code */
<?php
$string = "the string with linebreaks";
$string = strtr($string,array("."=>".\r\r",":"=>" : \r","-"=>"\r - "));
?>
And the CSS :
.your_textarea_class {
style='white-space:pre-wrap';
}
You can do the same with regex (I'm learning how to build regex with pregreplace using an associative array, seems to be better for adding the \n\r which makes the breaks display).