473,372 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 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 7958
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: dan glenn | last post by:
hi. I'm having a problem using javasript to pass the value of a textarea (in a form) to a PHP script file. I want to code a 'preview' function into a guestbook entry page, using an HTML link...
2
by: John Ramsden | last post by:
I have a form containing a table whose cells include prompt text strings and input areas, one of which is a textarea. These are specified using only percent values, and I use some simple...
2
by: Jerome | last post by:
Hi, I know this is an old question but I don't find the solution on the 'net ... The user enters his data into a multiline textarea field. The data is saved in a TEXT field in a database on a...
21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
1
by: IkBenHet | last post by:
Hello, I found this script to create a simple rich text form (http://programmabilities.com/xml/index.php?id=17): <html> <head> <title>Rich Text Editor</title> </head> <body>
4
by: Les Juby | last post by:
Can someone please help with a suggestion as to how I can keep the formatting (carriage returns) that the user enters into a memo field and then display that later. I figured I might be able to...
7
by: mattrapoport | last post by:
I have a page with a div on it. The div displays a user comment. When the user logs into this page, their current comment is pulled from a db and displayed in the div. The user can edit the...
1
by: simbarashe | last post by:
Hie could someone please help me with getting and using the current page url. I have a function that gets the url, I want to use it with header(location : XXX) but it wont work. The code is as...
11
by: Elizabeth Barnwell | last post by:
We've built this tool to help with the process of learning programming languages. You can use material on the site, or add your own to study. We've just rolled out a lot of changes to YoYoBrain, so...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.