Single and double quote problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • davegraham_1998@yahoo.com

    Single and double quote problem

    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 handleDeletePar ts('ABC', 'MY
    DESCRIPTION')">

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

    The problem is if there is a single quote (translated to &#39;) 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 handleDeletePar ts("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 handleDeletePar ts('XF2',
    '&#39;Mustang&# 39; Logo Fabric Bucket Seats')">

    Any help is appreciated.

  • humbads

    #2
    Re: Single and double quote problem

    Use String.fromChar Code(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.fromCh arCode(39)+'

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

    fromCharCode documentation at MSDN:


    Comment

    Working...