Apostrophies in names/strings

Discussion in 'JavaScript' started by BrackishWater, Jul 31, 2007.

  1. #1
    I have declared in my JSP a select tag with the following:

    onChange = "onChangeAction('<%=action%>', '<%=id%>', '<%=key%>', '<%=pageNum%>')"

    the problem is that the key includes a username so when the user's name is O'Reilly I get this:

    onChange = "onChangeAction('1', '20', '775954255_O'REILLY', '1')"

    ...naturally this breaks the entire page since the apostrophie hoses up that string. Anyone have an idea how to resolve this?
     
    BrackishWater, Jul 31, 2007 IP
  2. rgchris

    rgchris Peon

    Messages:
    187
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Escape them with slashes.
     
    rgchris, Jul 31, 2007 IP
  3. BrackishWater

    BrackishWater Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I tried with slashes for apostrophes and quotation marks. Same error.
     
    BrackishWater, Jul 31, 2007 IP
  4. disco_danny

    disco_danny Peon

    Messages:
    12
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try replacing it with the acsii code.

    Something like this -
    replace(/\'/g, "&#39;");

    then have your jsp or java convert it back.
     
    disco_danny, Jul 31, 2007 IP