Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unterminated string constant 1

Status
Not open for further replies.

jojo79

Programmer
Oct 11, 2006
40
US
I am getting the following error."Unterminated string constant" It shows the error hapending at:

alert('<%=bid
----------------^

Does anyone have a clue, i have tried just about everything.

I am just trying to alert the Request.QueryString("q").

Code:
<%
Dim bid
bid = Request.QueryString("q")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/_database/BuckleyAssc.mdb")

Set rs = Server.CreateObject("ADODB.Recordset")
sql = "SELECT COMPANY, ADDRESS, CITY, STATE, ZIP FROM BILL WHERE BILLID = '" & Request.QueryString("q") &"'"
rs.Open sql, conn

response.write("<table>")
do until rs.EOF
for each x in rs.Fields
response.write("<tr><td style=""FONT-SIZE: 10px; padding-left: 60px; FONT-FAMILY: Tahoma"">" & x.value & "</td></tr>")
next
rs.MoveNext
loop
response.write("<tr><td style=""FONT-SIZE: 10px; padding-left: 60px; FONT-FAMILY: Tahoma""><input name="""" type=""button"" onClick=""alert('<%=bid%>')"" value=""Delete"" /></td></tr>")

response.write("</table>")

%>
 
Its no wonder with so many escaped quotes on one line.
[tt]
rs.MoveNext
loop
%>

<tr>
<td style="FONT-SIZE: 10px; padding-left: 60px; FONT-FAMILY: Tahoma">
<input name=""
type="button"
onClick="alert('[highlight]<%=bid%>[/highlight]')"
value="Delete"/>
</td>
</tr>
[/tt]


also, in the original version, it looks like the code was going to print the highlighted server-side code to the client rather than executing it on the server.
 
man, I never thought to close script and then open another one. Thanks Sheco, One more quick question, Why do i need to use so many escape quotes in the first sections and not the second one???? Thanks again.
 
Well you could just as well do this:
Code:
...

do until rs.EOF
  for each x in rs.Fields
%>
 <tr>
   <td style="FONT-SIZE: 10px; padding-left: 60px; FONT-FAMILY: Tahoma"> 
     <%= x.value%> 
   </td>
 </tr>
<%
next
rs.MoveNext
loop
%>
  <tr>
    <td style="FONT-SIZE: 10px; padding-left: 60px; FONT-FAMILY: Tahoma">
      <input name="" 
             type="button" 
             onClick="alert('<%=bid%>')"
             value="Delete"/>
    </td>
  </tr>


Another thing you can do is use single quotes for the HTML output. The browser seems to see the following as the same:
[tt]<div class="foo">[/tt] and [tt]<div class='foo'>[/tt]

This might not be technically w3.org valid but it works and is easier than escaping quotes.
 
I think I am going crazy. I am now getting an error saying that 'test' is undefined. Anyone with any reasons, I defined the var on the page.

bid =Request.QueryString("q") which for this example = 'test'

Code:
<%
Dim bid
bid = Request.QueryString("q")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/_database/BuckleyAssc.mdb")

Set rs = Server.CreateObject("ADODB.Recordset")
sql = "SELECT COMPANY, ADDRESS, CITY, STATE, ZIP, BILLID FROM BILL WHERE BILLID = '" & Request.QueryString("q") &"'"
rs.Open sql, conn

response.write("<table>")
do until rs.EOF
for each x in rs.Fields
response.write("<tr><td style=""FONT-SIZE: 10px; padding-left: 60px; FONT-FAMILY: Tahoma"">" & x.value & "</td></tr>")
next
  rs.MoveNext
loop
%>

  <tr>
    <td style="FONT-SIZE: 10px; padding-left: 60px; FONT-FAMILY: Tahoma">
<input name="" type="button" value="Delete Record" onclick="alert(<%=bid%>)"/>
    </td>
  </tr>
 
Just to clarify...

Are you getting a browser-side error message on the following:[tt]
onClick="alert('test')"[/tt]

Or are you describing a server-side error?
 
I had an extra "'" in my code. I am sorry for the confusion. Thank you so much for your help. I was killing myself over this. Have a great rest of the week.
 
Why do i need to use so many escape quotes in the first sections and not the second one
Because in the first section the quotes are contained in VBScript code, and so must be escaped. In the second section there is no VBScript, it's just pure HTML, so the quotes do not need to be escaped.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top