Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ESCAPE tic marks (') in javascript and jsp???

 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a link in my jsp page that calls a javascript function. The values I pass into the function are determined dynamically. My question is how do I escape tic marks (') when calling the function? My code is:
<A href="javascript: diffVisit('<%= visit.getAccountNumber() %>','<%= visit.getRoomBed() %>','<%= visit.getAdmitDateFormatted() %>','<%= visit.getDischargeDateFormatted() %>','<%= visit.getAdmittingDiagnosis() %>','<%= i %>', '<%= visit.getAttendingDoctor().getNameLastNameFirst() %>', '<%= visit.getHeight() %>', '<%= visit.getWeight() %>', '<%= visit.getReferringDoctor().getNameLastNameFirst() %>', '<%= visit.getLengthOfStay() %>', '<%= visit.getConsultingDoctor().getNameLastNameFirst() %>', '<%= visit.getDischargeDisposition() %>');"><%= visit.getAdmitDateFormatted() %></A>
When the values are filled in, some of the names could be O'Mally or O'Brian. With the tics in the name, this causes the javascript not to execute properly. For example, the above becomes:
<A href="javascript: diffVisit('0000524357','652157','12/09/1999','','UNSTABLE','0', 'PULLMANN MD, DANIEL E', '6 ft. 2 in.', '172 lbs.', 'O'DOWD MD, MARY K', '0', 'O'MALLY MD, JERRY H', 'Discharged to home');">12/09/1999</A>
Any ideas on how to solve the above situation is greatly appreciated!!
 
Kelley Koszegi
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I believe a '\' can be used as an escape character.
Thanks,
--Kksozegi
 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response, Kelley. I have tried using '\' as an escape character, and that seems to work. Now I am writing a utility method to check for tics and escape them before sending them to the javascript function. However, I'm missing something in my function:

For example, when I send in "6' 2''", the method returns "6\' 2\''" instead of "6\' 2\'\'". I've tried using indexOf("'") and indexOf('\''), but neither seem capable of capturing the last ' and escaping it correctly. I know this is a small mistake, but I can't see what I'm doing wrong. Your corrections are appreciated!
[This message has been edited by verduka fox (edited August 22, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic