UGH! Using escape characters don't work...anyone know why?

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

    UGH! Using escape characters don't work...anyone know why?

    Hi, not sure this is the right group, but hoping someone may have
    experienced this.

    I'm passing html text as a parameter to a javascript. When it has an
    apostrophe in it, of course it does parse correctly. BTW, using IE6
    and msxml3/4.

    Even if I manually escape the ' with \' or '' the browser just sees it
    as \' or '' and not as an escaped apostrophe.

    This is driving me nuts! Everyone just tells me to escape the
    character.

    Any clues most welcome!

    Thanks, Kathy
  • Jim Ley

    #2
    Re: UGH! Using escape characters don't work...anyone know why?

    On 11 Oct 2003 07:22:11 -0700, KathyBurke40@at tbi.com (KathyB) wrote:
    [color=blue]
    >I'm passing html text as a parameter to a javascript. When it has an
    >apostrophe in it, of course it does parse correctly.[/color]

    If it parses correctly, what's your problem...

    You might try actually illustrating your problem with code, or a link,
    you're not even telling us how you're "passing html text as a
    parameter to a javascript"

    Jim.
    --
    comp.lang.javas cript FAQ - http://jibbering.com/faq/

    Comment

    • Lee

      #3
      Re: UGH! Using escape characters don't work...anyone know why?

      KathyB said:[color=blue]
      >
      >Hi, not sure this is the right group, but hoping someone may have
      >experienced this.
      >
      >I'm passing html text as a parameter to a javascript. When it has an
      >apostrophe in it, of course it does parse correctly. BTW, using IE6
      >and msxml3/4.
      >
      >Even if I manually escape the ' with \' or '' the browser just sees it
      >as \' or '' and not as an escaped apostrophe.
      >
      >This is driving me nuts! Everyone just tells me to escape the
      >character.
      >
      >Any clues most welcome![/color]

      You need to provide more detail. A link to a page or a small sample
      of code that shows the problem would help.
      Did you mean to say "of course it does NOT parse correctly" ?

      How are you passing the HTML text?

      Escape characters have no meaning in HTML.
      Escape characters only have meaning in literal text.
      They are ignored in text that is already in the value of a variable.
      For example, the following code will produce a page reading:

      Kathy\'s problem
      Kathy\'s problem
      Kathy's problem

      <html>
      <body>
      <div id="alpha">Kath y\'s problem</div>
      <script type="text/javascript">
      document.write( document.getEle mentById("alpha ").innerHTM L);
      document.write( "<br>Kathy\ 's problem");
      </script>
      </body>
      </html>


      <html>
      <body>
      <div id="alpha">Kath y\'s problem</div>
      <script type="text/javascript">
      document.write( document.getEle mentById("alpha ").innerHTM L);
      document.write( "<br>Kathy\ 's problem");
      </script>
      </body>
      </html>

      Kathy\'s problem
      Kathy\'s problem
      Kathy's problem

      Comment

      • Kathy Burke

        #4
        Re: UGH! Using escape characters don't work...anyone know why?

        Yes, I DID mean that it does NOT parse correctly. Here is an example of
        my script and parameter passed.

        <script language="Javas cript">
        function Anomaly(textIn)
        {
        newWindow = window.open(('A nomaly.aspx?des c=' +textIn), 'Anomaly',
        'width=650,heig ht=700');
        }
        </script>

        <input type="button" value="Anomaly"
        onclick="Javasc ript:Anomaly('K athy's apostrophe test')">

        QUESTION: What does the parameter have to be to not throw an exception
        within the script? I've tried \' but it just results in \' in the html
        output not just the html source.

        I hope this clarifies my question. Thanks for responding!

        Kathy



        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: UGH! Using escape characters don't work...anyone know why?

          Kathy Burke <kathyburke40@a ttbi.com> writes:
          [color=blue]
          > Yes, I DID mean that it does NOT parse correctly. Here is an example of
          > my script and parameter passed.
          >[/color]
          [color=blue]
          > <input type="button" value="Anomaly"
          > onclick="Javasc ript:Anomaly('K athy's apostrophe test')">[/color]
          ^
          The problem is here: ^
          That single-quote/apostrophe must be escaped.
          [color=blue]
          > QUESTION: What does the parameter have to be to not throw an exception
          > within the script? I've tried \' but it just results in \' in the html
          > output not just the html source.[/color]

          The onclick event should be:
          onclick="Anomal y('Kathy\'s apostrophe test')">

          Drop the "Javascript :". It doesn't belong there, and it makes no
          difference.


          Other comments:
          [color=blue]
          > <script language="Javas cript">[/color]

          This should be
          <script type="text/javascript">
          The type attribute is required in HTML 4 and later.
          [color=blue]
          > newWindow = window.open(('A nomaly.aspx?des c=' +textIn), 'Anomaly',[/color]

          Not all characters are allowed in URL's, so I would suggest changing
          "textIn" to "escape(textIn) ". That will write characters that are
          not allowed in URL's as, e.g., %20 (a space).

          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • Allan W

            #6
            Re: UGH! Using escape characters don't work...anyone know why?

            KathyBurke40@at tbi.com (KathyB) wrote

            I think what you're asking is how to nest quotes. For instance, if you
            want to use document.write( ) to write out a statement that has a quote
            in it.

            If so, the answer is that most places that need quotes, can use either
            single quotes or double quotes.

            document.write( "Kathy's page"); // Quoted string contains
            apostrophe
            shows up as
            Kathy's page

            document.write( 'Is "Kathy" home?"); // Quoted string contains
            quote
            shows up as
            Is "Kathy" home?

            If you find that you need to use both, you can use the + sign to
            concatenate.

            document.write( 'Is this "Kathy' + "'s Page" +'"?');
            shows up as
            Is this "Kathy's Page"?

            HTH
            [color=blue]
            > Hi, not sure this is the right group, but hoping someone may have
            > experienced this.
            >
            > I'm passing html text as a parameter to a javascript. When it has an
            > apostrophe in it, of course it does parse correctly. BTW, using IE6
            > and msxml3/4.
            >
            > Even if I manually escape the ' with \' or '' the browser just sees it
            > as \' or '' and not as an escaped apostrophe.
            >
            > This is driving me nuts! Everyone just tells me to escape the
            > character.
            >
            > Any clues most welcome!
            >
            > Thanks, Kathy[/color]

            Comment

            Working...