473,666 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="popawi ndow(500,400,'p reviewgbmsg.php ?t='
+window.documen t.signupform.me ssage.value);re turn 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.p hp' 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.do cument.signupfo rm.message.valu e);

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 1833
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********@yah oo.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="popawi ndow(500,400,'p reviewgbmsg.php ?t='
+window.docume nt.signupform.m essage.value);r eturn 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.p hp' 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.do cument.signupfo rm.message.valu e);

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********@yah oo.com> wrote:
For the 'Preview' link i have:

<a href="#" onClick="popawi ndow(500,400,'p reviewgbmsg.php ?t='
+window.documen t.signupform.me ssage.value);re turn 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.p hp' 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.p hp?t=' + escape( window.document .signupform.mes sage.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.******@blueyo nder.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.******@bluey onder.co.invali d> wrote in message
news:op******** ******@news-text.blueyonder .co.uk...
On Thu, 08 Jan 2004 08:23:37 GMT, dan glenn <da********@yah oo.com> wrote:
For the 'Preview' link i have:

<a href="#" onClick="popawi ndow(500,400,'p reviewgbmsg.php ?t='
+window.documen t.signupform.me ssage.value);re turn 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.p hp' 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.p hp?t=' + escape(

window.document .signupform.mes sage.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.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

Jul 20 '05 #4
In article <op************ **@news-text.blueyonder .co.uk>, Michael Winter
<M.******@bluey onder.co.invali d> 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.signup form.message.va lue

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.******@bluey onder.co.invali d> 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.signup form.message.va lue

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.******@blueyo nder.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.signup form.message.va lue


Mozilla.
With shorter names:
<form id="foo"><inpu t name="bar" value="baz"></form>
and
document.foo.ba r.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/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7972
by: dan glenn | last post by:
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...
2
14151
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 javascript to expand the table to the available window width. So whether the screen is maximized or partially minimized, the table fits snugly in the available display. The trouble is if I include a 'cols=' spec for the textarea box its width stays...
2
1783
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 SQL Server. I want to display that data now, but the carriage returns should be replaced with <br>! Otherwise the text doesn't have paragraphs. How do I do that?
21
3963
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 nothing in IE. I'd be greatful for any assistance. Also, if I will have problems the code on Opera or Safari, I'd appreciate any pointers--I don't have a Mac to test Safari. THanks very much, Michael
1
3746
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
7315
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 use: 'replace carriage returns with BRs comment=Replace(comment, chr(13), "<br>") but obviously net.! The <pre> tag doesn't sem to help either as the embedded return is
7
11187
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 comment through a pop-up that contains a textarea. When the user hits OK on the pop-up, the text in the textarea is sent to a function on the main page. The function inserts the text into the div's text node. Please don't ask why I'm making this...
1
18847
by: den2005 | last post by:
Hi everybody, I am confused and still looking why this codes is not working. Can anyone notice or know why this code is not working? Thanks in advance. Code working: <form id="form1" runat="server"> <div> &nbsp;</div> <div>
1
3188
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 follows: The code below is for the first page:session_start is in line 3 <link href="css/jobSheet.css" rel="stylesheet" type="text/css" /> session_start();
11
243
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 feedback is much appreciated. http://www.yoyobrain.com/subjects/show/240 Thanks, Elizabeth
0
8448
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8871
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7387
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2773
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.