not getting returns with javascript grab of textarea

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

    #1

    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


  • Brynn

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

    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" <dan_danboy@yah oo.com>
    wrote:
    [color=blue]
    >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
    >
    >[/color]

    Comment

    • Michael Winter

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

      On Thu, 08 Jan 2004 08:23:37 GMT, dan glenn <dan_danboy@yah oo.com> wrote:
      [color=blue]
      > 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.[/color]

      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.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

      Comment

      • dan glenn

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

        Michael - You da MAN!!!

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

        -dg

        "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
        news:opr1gumcjq 5vklcq@news-text.blueyonder .co.uk...[color=blue]
        > On Thu, 08 Jan 2004 08:23:37 GMT, dan glenn <dan_danboy@yah oo.com> wrote:
        >[color=green]
        > > 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.[/color]
        >
        > 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([/color]
        window.document .signupform.mes sage.value[color=blue]
        > )
        >
        > 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.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)[/color]


        Comment

        • HikksNotAtHome

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

          In article <opr1gumcjq5vkl cq@news-text.blueyonder .co.uk>, Michael Winter
          <M.Winter@bluey onder.co.invali d> writes:
          [color=blue]
          >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[/color]

          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

          Comment

          • Michael Winter

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

            On 08 Jan 2004 23:00:00 GMT, HikksNotAtHome <hikksnotathome @aol.com> wrote:
            [color=blue]
            > In article <opr1gumcjq5vkl cq@news-text.blueyonder .co.uk>, Michael Winter
            > <M.Winter@bluey onder.co.invali d> writes:
            >[color=green]
            >> 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[/color]
            >
            > Like a nightmare that won't end, its me again.[/color]

            You like picking on me, don't you*. :P
            [color=blue]
            > 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.[/color]

            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.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

            Comment

            • Lasse Reichstein Nielsen

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

              hikksnotathome@ aol.com (HikksNotAtHome ) writes:
              [color=blue]
              > 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[/color]

              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 - lrn@hotpop.com
              DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
              'Faith without judgement merely degrades the spirit divine.'

              Comment

              Working...