not getting returns with javascript grab of textarea

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dan glenn

    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="popawi ndow(500,400,'p reviewgbmsg.php ?t='+window.doc ument.signupfor m
    ..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.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. grrrr

    I know that in pure javascript, if i do:

    Alert(window.do cument.signupfo rm.message.valu e);

    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


  • Pedro Graca

    #2
    Re: not getting returns with javascript grab of textarea

    dan glenn wrote:[color=blue]
    > I know that in pure javascript, if i do:
    >
    > Alert(window.do cument.signupfo rm.message.valu e);
    >
    > 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?[/color]

    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,

    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--

    Comment

    • dan glenn

      #3
      Re: not getting returns with javascript grab of textarea

      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.valu e)) 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" <hexkid@hotpop. com> wrote in message
      news:btjada$7ru cp$1@ID-203069.news.uni-berlin.de...[color=blue]
      > dan glenn wrote:[color=green]
      > > I know that in pure javascript, if i do:
      > >
      > > Alert(window.do cument.signupfo rm.message.valu e);
      > >
      > > i will see all hard returns in the alert window. So one would THINK that[/color][/color]
      the[color=blue][color=green]
      > > 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[/color][/color]
      difference[color=blue][color=green]
      > > the WRAP setting in the Textarea tag, by the way). Is there a way I can[/color][/color]
      pass[color=blue][color=green]
      > > a <Textarea>'s current value to a PHP script file, included any hard[/color][/color]
      returns[color=blue][color=green]
      > > it may have?[/color]
      >
      > 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);[/color]
      ?></b>][color=blue]
      >
      > #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 =--[/color]


      Comment

      • Chung Leong

        #4
        Re: not getting returns with javascript grab of textarea

        Another way to do this is to have previewgbmsg.ph p reach back into the
        original window and grab the text.

        var text = window.opener.d ocument.forms.s ignupform.messa ge.value;

        Uzytkownik "dan glenn" <dan_danboy@yah oo.com> napisal w wiadomosci
        news:Ci8Lb.1322 $4W5.58@newssvr 29.news.prodigy .com...[color=blue]
        > 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[/color]
        javascript[color=blue]
        > to grab the form's textarea value, and open another browser window that[/color]
        uses[color=blue]
        > a php file that applies all the styles, etc. to the contents of what was[/color]
        in[color=blue]
        > the text area (the guestbook entries allow simple HTML) and show the[/color]
        preview[color=blue]
        > that way. The user can just close this window and he's right where he was[/color]
        on[color=blue]
        > the guestbook entry form.
        >
        > For the 'Preview' link i have:
        >
        > <a href="#"
        >[/color]
        onClick="popawi ndow(500,400,'p reviewgbmsg.php ?t='+window.doc ument.signupfor m[color=blue]
        > .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.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[/color]
        textarea[color=blue]
        > are not coming over. grrrr
        >
        > I know that in pure javascript, if i do:
        >
        > Alert(window.do cument.signupfo rm.message.valu e);
        >
        > i will see all hard returns in the alert window. So one would THINK that[/color]
        the[color=blue]
        > 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[/color]
        pass[color=blue]
        > a <Textarea>'s current value to a PHP script file, included any hard[/color]
        returns[color=blue]
        > it may have?
        >
        > thanks,
        > -dg
        >
        >[/color]


        Comment

        Working...