This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes ESCAPE tic marks (') in javascript and jsp??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "ESCAPE tic marks ( Watch "ESCAPE tic marks ( New topic
Author

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

verduka fox
Ranch Hand

Joined: Jan 18, 2001
Posts: 178
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

Joined: Aug 20, 2001
Posts: 27
Hello,
I believe a '\' can be used as an escape character.
Thanks,
--Kksozegi


Kelley Koszegi<br />Sun Certified Java Programmer
verduka fox
Ranch Hand

Joined: Jan 18, 2001
Posts: 178
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).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ESCAPE tic marks (') in javascript and jsp???
 
Similar Threads
How to pass an arrayList from a JSP to a servlet.
Javascript escape() function to handle an XML containing international characters
using EL to get the keySet of a HashMap
Windows XP Popup blocking
Calling javascript function from jsp