470,815 Members | 1,324 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

not getting returns with javascript grab of textarea

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 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.

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 I use that opens another
browser window (of size 500x400 here), 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.

I know that in pure javascript, if i do:

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

i will see all hard returns that may have been in the textarea in the alert
message window. So one would THINK that the object value expression SHOULD
be returning hard returns, at least in some way (i haven't a clue how) in my
t='+window.doc...etc 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? Is there some way I can "pre-process" the textarea value so I
can put it into the 'get' for my php file?

thanks,
-dg
Jul 20 '05 #1
6 1673
Will hard returns passs in a querystring? I am not sure, haven't
tested ... in any case, try replacing them with @@@ and switching them
back on the other page.
On Thu, 08 Jan 2004 08:23:37 GMT, "dan glenn" <da********@yahoo.com>
wrote:
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 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.

For the 'Preview' link i have:

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

Note that 'popawindow' is just a javascript program I use that opens another
browser window (of size 500x400 here), 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.

I know that in pure javascript, if i do:

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

i will see all hard returns that may have been in the textarea in the alert
message window. So one would THINK that the object value expression SHOULD
be returning hard returns, at least in some way (i haven't a clue how) in my
t='+window.doc...etc 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? Is there some way I can "pre-process" the textarea value so I
can put it into the 'get' for my php file?

thanks,
-dg


Jul 20 '05 #2
On Thu, 08 Jan 2004 08:23:37 GMT, dan glenn <da********@yahoo.com> wrote:
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 I use that opens
another
browser window (of size 500x400 here), 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.


You can't have them in URIs - that's why. If you submitted the data as
part of a form (and I'd recommend changing to POST if you did that), the
new-lines would be escaped automatically. However, because you're creating
the URI, that conversion isn't performed.

Simply call escape() on the the value before appending it. That is:

'previewgbmsg.php?t=' + escape( window.document.signupform.message.value
)

PHP can unescape the string with urldecode().

An aside: use the collection syntax to reference form controls - it will
allow your code to work across more browsers. The above reference should
be written as:

document.forms['signupform'].elements['message'].value

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #3
Michael - You da MAN!!!

Works beautifully. Thanks a lot, also for the tip on the 'collection
syntax'.

-dg

"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk...
On Thu, 08 Jan 2004 08:23:37 GMT, dan glenn <da********@yahoo.com> wrote:
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 I use that opens
another
browser window (of size 500x400 here), 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.
You can't have them in URIs - that's why. If you submitted the data as
part of a form (and I'd recommend changing to POST if you did that), the
new-lines would be escaped automatically. However, because you're creating
the URI, that conversion isn't performed.

Simply call escape() on the the value before appending it. That is:

'previewgbmsg.php?t=' + escape(

window.document.signupform.message.value )

PHP can unescape the string with urldecode().

An aside: use the collection syntax to reference form controls - it will
allow your code to work across more browsers. The above reference should
be written as:

document.forms['signupform'].elements['message'].value

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)

Jul 20 '05 #4
In article <op**************@news-text.blueyonder.co.uk>, Michael Winter
<M.******@blueyonder.co.invalid> writes:
An aside: use the collection syntax to reference form controls - it will
allow your code to work across more browsers. The above reference should
be written as:

document.forms['signupform'].elements['message'].value


Like a nightmare that won't end, its me again.

Is there a browser where this works:
document.forms['signupform'].elements['message'].value

But this doesn't - assuming message isn't a select list or a radio button[1]?

document.signupform.message.value

I am truly curious this time.

[1] It is known that NN4.xx won't give a select that way. Radios are a beast of
there own.
--
Randy
Jul 20 '05 #5
On 08 Jan 2004 23:00:00 GMT, HikksNotAtHome <hi************@aol.com> wrote:
In article <op**************@news-text.blueyonder.co.uk>, Michael Winter
<M.******@blueyonder.co.invalid> writes:
An aside: use the collection syntax to reference form controls - it will
allow your code to work across more browsers. The above reference should
be written as:

document.forms['signupform'].elements['message'].value
Like a nightmare that won't end, its me again.


You like picking on me, don't you*. :P
Is there a browser where this works:
document.forms['signupform'].elements['message'].value

But this doesn't - assuming message isn't a select list or a radio
button[1]?

document.signupform.message.value

I am truly curious this time.


To be perfectly honest, I can't answer that. I don't have enough
experience of the numerous browsers out there (I'm limited to Opera and,
previously, IE**).

Whether there is, or there isn't, this syntax has a couple of advantages:

1) If you decided to use operators or spaces in your attribute values, you
wouldn't have to switch just for that special case.
2) [Related to (1)] It's a consistent syntax, because it works with or
without special characters.
3) It has been mentioned in other threads that that syntax conforms to
DOM, so it should be guaranteed for the foreseeable future.
4) If there are browsers that don't accept the simple, short dot notation,
your code will work fine for them.

The only argument against it is the size, but I would think that is only a
problem for the developer in that it's somewhat cumbersome, not that it
adds too many bytes to the filesize. With sensible use of references, the
impact of the verbosity is negated anyway, so all you're left with is
overhead.

Mike
* Just kidding! :D
** I sometimes use Konqueror, but I stay away from Mozilla and Netscape -
I don't like the interface :) I'll be giving FireBird a go though when it
reaches the Release state.

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #6
hi************@aol.com (HikksNotAtHome) writes:
Is there a browser where this works:
document.forms['signupform'].elements['message'].value

But this doesn't - assuming message isn't a select list or a radio button[1]?

document.signupform.message.value


Mozilla.
With shorter names:
<form id="foo"><input name="bar" value="baz"></form>
and
document.foo.bar.value
Mozilla gives:
TypeError: document.foo has no properties
while
document.forms['foo'].elements['bar'].value
gives "baz" as it should.

If you had name="foo" in the form, then document.foo would work,
but that's another story.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by dan glenn | last post: by
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
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.