By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,818 Members | 2,121 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,818 IT Pros & Developers. It's quick & easy.

Insert a carriage return in a JavaScript string

P: n/a
Hi,

I've got some JavaScript inserted within a PHP echo instruction:
<?php>
echo " ... javascript ...."
<?>

This context may be important, I don't know...
At some point within the JavaScript, I want to add a carriage return at
the end of a field value:
str = str + '\n';

but this writting does not work, because the Javascript produced in the
html page gives:
str = str + '
'
How to do this?

Thanks.

Herve.

Sep 12 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"yellowtek" <hm*****@tele2.frwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi,

I've got some JavaScript inserted within a PHP echo instruction:
<?php>
echo " ... javascript ...."
<?>

This context may be important, I don't know...
At some point within the JavaScript, I want to add a carriage return at
the end of a field value:
str = str + '\n';

but this writting does not work, because the Javascript produced in the
html page gives:
str = str + '
'
How to do this?
FYI:
str +' "\n"
is the same as
str = str + '\n';

Depending on your usage you may have to "escape"
the backslash; for example \\n.

However, "<br>" may be applicable instead.

What causes the "Javascript produced in the html page"?

Show us your code...

Sep 12 '06 #2

P: n/a
The javascript "produced" is what you get in the browser as a source
code when the PHP page is executed, that is:
echo "... javascript.....";

And the reason of the insertion of JavaScript within this PHP echo is
the share of PHP constants:
<?php>
include ("inc/constants.inc.php");
echo "
str = str + '".A_CONSTANT."';
";
<?>

I will try the double \; that might be the solution.
Thanks.

McKirahan a écrit :
"yellowtek" <hm*****@tele2.frwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi,

I've got some JavaScript inserted within a PHP echo instruction:
<?php>
echo " ... javascript ...."
<?>

This context may be important, I don't know...
At some point within the JavaScript, I want to add a carriage return at
the end of a field value:
str = str + '\n';

but this writting does not work, because the Javascript produced in the
html page gives:
str = str + '
'
How to do this?

FYI:
str +' "\n"
is the same as
str = str + '\n';

Depending on your usage you may have to "escape"
the backslash; for example \\n.

However, "<br>" may be applicable instead.

What causes the "Javascript produced in the html page"?

Show us your code...
Sep 12 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.