?
Solved

Double to single to double quotes

Posted on 2006-04-21
5
Medium Priority
?
209 Views
Last Modified: 2012-06-27
Hello-

Where it says "<%=getdata("description")%>", may have single quotes inside. How can I keep Javascript from erring out when it sees that inside the string? Do I need double quote twice then single outside or?

Thanks

<img src="yourSrc" name="Photo" />
<span id="PhotoDescription"></span>

ONMOUSEDOWN="document.images['Photo'].src='/mypictures/pic.jpg'; document.getElementById('PhotoDescription').innerHTML = '<%=getdata("description")%>';"

0
Comment
Question by:jfergy
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:BogoJoker
ID: 16512352
You should use an asp function, in php there i mysql_real_escape_string($description) let me see if there is a simliar function for ASP.
0
 
LVL 17

Accepted Solution

by:
BogoJoker earned 200 total points
ID: 16512366
I did not see any particular one, somebody did make a function, which is simple:

<%
function stripQuotes(strWords)
stripQuotes = replace(strWords, "'", "\'")
end function
%>

Put that at the top then use:
<%=stripQuotes(getdata("description"))%>

Now all quotes, when they come out of that will be escaped (Example \') for the javascript to read as just a single quote.
Joe P
0
 

Author Comment

by:jfergy
ID: 16512384
Thanks that worked great. I made it a little simpler though:

<%=Replace(getpix("Description"), "'", "\'")%>
0
 
LVL 17

Expert Comment

by:BogoJoker
ID: 16512429
Hehe, nice thinking, I'm no good with ASP, I am a php guy =)
0
 

Author Comment

by:jfergy
ID: 16512517
Thanks for the help. I used php quite a while ago until Microsoft servers caught up to the usability of apache. Now im just MS.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question