?
Solved

String termination and invalid character error!

Posted on 2003-02-26
10
Medium Priority
?
254 Views
Last Modified: 2012-06-27
Hi There,

Im having errors while running this code .The code is fine but the values coming from the database fields r clashing with it.
check it plz..
---

<%      rs.open "select * from comp_specs"
        while not rs.eof
%>
<a href="#" onClick="opener.document.form1.heading.value='<%=rs("heading")%>';">
<%=rs("record_id")%>--<%=rs("heading")%>--<%=rs("description")%>
</a>
<br>        
<%      
        rs.movenext
        wend
        rs.close
%>
---
problem im facing is bcoz the rs("description") field have values such as this:

onClick='opener.document.form1.heading.value="Dimensions (H×W×D)";opener.document.form1.description.value="1.75" × 19"×27.63" (44.5×434.3×701.8,mm)";'

The double quotes r giving me problems .

what can done so that i dont get errors.
0
Comment
Question by:starshar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 4

Expert Comment

by:Wakie
ID: 8024911
Where are you writing an onClick event inside on an A HREF tag?
0
 
LVL 4

Expert Comment

by:Wakie
ID: 8024917
Type: "Why"
0
 
LVL 4

Expert Comment

by:Wakie
ID: 8024918
Typo: "Why"
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:starshar
ID: 8024940
yes inside the a href ..
on page 1 on click of a button ,a new window pops up which shows the various records and the clicked values is going to the main page in a text box..

hope it helps

0
 
LVL 28

Expert Comment

by:sybe
ID: 8025026
Try using Server.HTMLEncode


<%=Server.HTMLEncode("" & rs("heading"))%>

The "" & is because Server.HTMLEncode will generate an error if the value of rs("heading") is null

0
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 8025118
I would do this:

onClick="opener.document.form1.heading.value='Dimensions (HWWWD)';opener.document.form1.description.value='1.75\" W 19\"W27.63\" (44.5W434.3W701.8,mm)';"

Notice that I move the double quotes around the onclick handler (html 4 compliance there!).

Use single quotes to enclose the actual values, and use escape chaacters for double & single quotes.

I'd use this little VBScript function to produce JavaScript happy code:

Function MakeSafeForJS(sText)
    If IsNull(sText) Then Exit Function
    sText = Replace(sText, vbCrLf, "/n")
    sText = Replace(sText, "'", "/'")
    sText = Replace(sText, Chr(34), "/" & Chr(34))
    MakeSafeForJS = sText
End Function
0
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 8025129
<%      rs.open "select * from comp_specs"
       while not rs.eof
%>
<a href="#" onClick="opener.document.form1.heading.value='<%=MakeSafeForJS(rs("heading")%>)'; return false;">
<%=rs("record_id")%>--<%=rs("heading")%>--<%=rs("description")%>
</a>
<br>        
<%      
       rs.movenext
       wend
       rs.close
%>
0
 
LVL 1

Expert Comment

by:umangjoshi
ID: 8025142
pls try this

<%=replace(rs("heading"),"'","\'")%>
0
 
LVL 1

Accepted Solution

by:
CarMar earned 100 total points
ID: 8026214
Here's a solution:
The idea is to replace the double quotes from description by the escape character "%22".
Then by using a javascript function, we unescape the description and put the value in the form field.

IN HEAD SECTION USE THIS JAVASCRIPT:
====================================
<SCRIPT language="JavaScript" type="text/JavaScript">
<!--
function chgDesc(str) {
     opener.document.form1.description.value= unescape(str);
}
//-->
</SCRIPT>


On ASP:
=========
<%
Dim strNewDesc
Dim DQ : DQ = Chr(34) 'double quote "

     rs.open "select * from comp_specs"
    while not rs.eof

     strNewDesc = Replace(rs("description"), DQ, "%22")
%>

In the link, instead of using this:
onClick='opener.document.form1.heading.value="<%=rs("heading")%>";opener.document.form1.description.value="<%=rs("heading")%>";'

Use this:
onClick="opener.document.form1.heading.value='<%=rs("heading")%>';chgDesc('<% Response.Write strDesc %>');"

That's All!

---

SO, the link will become something like this (based on your example):
onClick="opener.document.form1.heading.value='Dimensions (HWWWD)';chgDesc('1.75%22 W 19%22W27.63%22 (44.5W434.3W701.8,mm)');"

It worked for me... it should work for you also ;)

BTW, there's also other solution:
Instead of replacing the double quotes by %22 you could replace it by a special character, like |
Then, in javascript you could use a function to replace the special character by the quotes.

Carlos

0
 

Author Comment

by:starshar
ID: 8027508
Thank You All !!!

many thanks to Carlos .
it worked nicely without any errors..

Cheers !
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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

771 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