Single and double quote problem

Discussion in 'Javascript' started by davegraham_1998@yahoo.com, Mar 23, 2005.

  1. Guest

    Hi All-

    I'm pretty sure this have been discussed earlier, but couldn't find a
    solution to my problem.

    <input type="submit"
    value="Delete Parts"
    onclick="return handleDeleteParts('ABC', 'MY
    DESCRIPTION')">

    I'm using something (Struts ResponseUtils.filter()) which translate 'MY
    DESCRIPTION' in such a manner that a double quote is replaced by &quot;
    and a single quote to '

    The problem is if there is a single quote (translated to ') i get a
    javascript error (small error icon on the status bar)it says, "Error:
    Expected ")"

    if I change the above to:

    <input type="submit"
    value="Delete Parts"
    onclick='return handleDeleteParts("ABC", "MY
    DESCRIPTION")'>

    it works fine, but a new error is introduced in that now i run into the
    same problem is MY DESCRIPTION has a double quote in it.


    Here is an actual line:

    <input type="submit"
    DISABLED
    value="Delete Parts"

    onclick="return handleDeleteParts('XF2',
    ''Mustang' Logo Fabric Bucket Seats')">

    Any help is appreciated.
    , Mar 23, 2005
    #1
    1. Advertising

  2. humbads Guest

    Use String.fromCharCode(i) to replace the single and double quotes.

    For example, if your string is O'douls, and you want it enclosed in
    single quotes, replace the single quote with:

    '+String.fromCharCode(39)+'

    So an example line might look like:
    alert('O'+String.fromCharCode(39)+'douls');

    fromCharCode documentation at MSDN:
    http://tinyurl.com/6o3x6
    humbads, Mar 25, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    13,143
  2. Eric Layman
    Replies:
    3
    Views:
    616
    Rad [Visual C# MVP]
    Apr 14, 2007
  3. Evan
    Replies:
    1
    Views:
    382
    Marc 'BlackJack' Rintsch
    Nov 4, 2008
  4. Evan
    Replies:
    3
    Views:
    505
    Marc 'BlackJack' Rintsch
    Nov 4, 2008
  5. vikrant
    Replies:
    8
    Views:
    348
    vikrant
    May 17, 2007
Loading...

Share This Page