471,306 Members | 936 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

not getting returns with javascript grab of textarea

hi. I want to code a 'preview' function into a guestbook entry page. I can
do it with a button that posts, bringing up a whole new page showing a
preview of what has been entered, and then the user could hit a 'return to
entry form' button or some-such and go back to the form.

But what I want to do instead is just use an HTML link with some javascript
to grab the form's textarea value, and open another browser window that uses
a php file that applies all the styles, etc. to the contents of what was in
the text area (the guestbook entries allow simple HTML) and show the preview
that way. The user can just close this window and he's right where he was on
the guestbook entry form.

For the 'Preview' link i have:

<a href="#"
onClick="popawindow(500,400,'previewgbmsg.php?t='+ window.document.signupform
..message.value);return false;">Preview</a>

Note that 'popawindow' is just a javascript program that opens another
browser window (of size 500x400), using the 'previewgbmsg.php' PHP file,
with the GET argument that is passing the textarea's value text to the PHP
file to process.

Now, all this works just fine, EXCEPT that the hard returns in the textarea
are not coming over. grrrr

I know that in pure javascript, if i do:

Alert(window.document.signupform.message.value);

i will see all hard returns in the alert window. So one would THINK that the
object value expression SHOULD be returning hard returns in some way (i
haven't a clue how) in my t='+window.doc..ect expression.

Anyway, I'm not getting them. I get everything else. (Makes no difference
the WRAP setting in the Textarea tag, by the way). Is there a way I can pass
a <Textarea>'s current value to a PHP script file, included any hard returns
it may have?

thanks,
-dg
Jul 17 '05 #1
3 7837
dan glenn wrote:
I know that in pure javascript, if i do:

Alert(window.document.signupform.message.value);

i will see all hard returns in the alert window. So one would THINK that the
object value expression SHOULD be returning hard returns in some way (i
haven't a clue how) in my t='+window.doc..ect expression.

Anyway, I'm not getting them. I get everything else. (Makes no difference
the WRAP setting in the Textarea tag, by the way). Is there a way I can pass
a <Textarea>'s current value to a PHP script file, included any hard returns
it may have?


HTML does not display hard returns!
I don't know about JavaScript ... try this:

#v+

<?php
$t = '';
if (isset($_GET['t'])) {
$t = $_GET['t'];
}
?>
<form action="">
<textarea name="t"><?php echo $t; ?></textarea>
<input type="submit"/>
</form>

$t inside "pre" tags is [<b><pre><?php echo $t; ?></pre></b>]
<br/><br/>

$t with no "pre" tags is [<b><?php echo $t; ?></b>]
<br/><br/>

$t with no "pre" tags, but with nl2br() is [<b><?php echo nl2br($t); ?></b>]

#v-

and call the page with, for example,
http://localhost/testenter.php?t=one%0Atwo%0Athree
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
Thanks for the input Pedro. I know HTML pretty well - my code on the php
side was replacing hard returns with <BR> or <P> - that wasn't the issue.
The problem was solved (from input on a java script forum) by escaping in
javascript (i.e., escape(xxx.value)) in the anchor tag, so the hard returns
of the guestbook text were properly encoded, then using urldecode() on the
php side.

-dg

"Pedro Graca" <he****@hotpop.com> wrote in message
news:bt************@ID-203069.news.uni-berlin.de...
dan glenn wrote:
I know that in pure javascript, if i do:

Alert(window.document.signupform.message.value);

i will see all hard returns in the alert window. So one would THINK that the object value expression SHOULD be returning hard returns in some way (i
haven't a clue how) in my t='+window.doc..ect expression.

Anyway, I'm not getting them. I get everything else. (Makes no difference the WRAP setting in the Textarea tag, by the way). Is there a way I can pass a <Textarea>'s current value to a PHP script file, included any hard returns it may have?
HTML does not display hard returns!
I don't know about JavaScript ... try this:

#v+

<?php
$t = '';
if (isset($_GET['t'])) {
$t = $_GET['t'];
}
?>
<form action="">
<textarea name="t"><?php echo $t; ?></textarea>
<input type="submit"/>
</form>

$t inside "pre" tags is [<b><pre><?php echo $t; ?></pre></b>]
<br/><br/>

$t with no "pre" tags is [<b><?php echo $t; ?></b>]
<br/><br/>

$t with no "pre" tags, but with nl2br() is [<b><?php echo nl2br($t);

?></b>]
#v-

and call the page with, for example,
http://localhost/testenter.php?t=one%0Atwo%0Athree
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--

Jul 17 '05 #3
Another way to do this is to have previewgbmsg.php reach back into the
original window and grab the text.

var text = window.opener.document.forms.signupform.message.va lue;

Uzytkownik "dan glenn" <da********@yahoo.com> napisal w wiadomosci
news:Ci***************@newssvr29.news.prodigy.com. ..
hi. I want to code a 'preview' function into a guestbook entry page. I can
do it with a button that posts, bringing up a whole new page showing a
preview of what has been entered, and then the user could hit a 'return to
entry form' button or some-such and go back to the form.

But what I want to do instead is just use an HTML link with some javascript to grab the form's textarea value, and open another browser window that uses a php file that applies all the styles, etc. to the contents of what was in the text area (the guestbook entries allow simple HTML) and show the preview that way. The user can just close this window and he's right where he was on the guestbook entry form.

For the 'Preview' link i have:

<a href="#"
onClick="popawindow(500,400,'previewgbmsg.php?t='+ window.document.signupform .message.value);return false;">Preview</a>

Note that 'popawindow' is just a javascript program that opens another
browser window (of size 500x400), using the 'previewgbmsg.php' PHP file,
with the GET argument that is passing the textarea's value text to the PHP
file to process.

Now, all this works just fine, EXCEPT that the hard returns in the textarea are not coming over. grrrr

I know that in pure javascript, if i do:

Alert(window.document.signupform.message.value);

i will see all hard returns in the alert window. So one would THINK that the object value expression SHOULD be returning hard returns in some way (i
haven't a clue how) in my t='+window.doc..ect expression.

Anyway, I'm not getting them. I get everything else. (Makes no difference
the WRAP setting in the Textarea tag, by the way). Is there a way I can pass a <Textarea>'s current value to a PHP script file, included any hard returns it may have?

thanks,
-dg

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jerome | last post: by
7 posts views Thread by mattrapoport | last post: by
11 posts views Thread by Elizabeth Barnwell | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.