Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

String termination and invalid character error!

Posted on 2003-02-26
10
Medium Priority
?
259 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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

580 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