|
-
Oct 15th, 2002, 06:24 AM
#1
Thread Starter
Fanatic Member
Using JavaScript esc char \ **Resolved**
I'm trying to write out some javascript on the server ie below but it returns an invalid character error can anyone see where I'm going wrong here?
Code:
<td><input name=Dir_ID value=>
<%
Response.Write("<a href='http://directory.intra.bt.com/cgi/startup.cgi")
If Len(Request.Cookies("UserID")) Then
Response.Write("?search_for=" & Request.Cookies("UserID"))
End If
Response.Write("' onclick='javascript:openWin(this.href, 1);return false;' Title='Search for a Directory ID' onmouseover='window.status=\'\Search for a Directory ID\'\; return true' onmouseout='window.status=\'\'; return true'>Get ID </a>")
%></td>
Once run this is the result after the error
Code:
<td><input name=Dir_ID value='521282'>
<a href='http://directory.intra.bt.com/cgi/startup.cgi' onclick='javascript:openWin(this.href, 1);return false;' Title='Search for a Directory ID' onmouseover='window.status=\'\Search for a Directory ID\'\; return true' onmouseout='window.status=\'\'; return true'>Get ID </a>
</td>
Last edited by aconybeare; Oct 16th, 2002 at 03:53 AM.
-
Oct 16th, 2002, 03:40 AM
#2
Fanatic Member
Code:
Response.Write("' onclick='javascriptpenWin(this.href, 1);return false;' Title='Search for a Directory ID' onmouseover='window.status='\Search for a Directory ID'\; return true' onmouseout='window.status=''; return true'>Get ID </a>")
A few possible reasons:
1/ There is a lone ' at the start of the string you are writing the page which doesn't appear to be needed
2/ 'window.status='\Search for a Directory ID'\ <- When using javascript document.write on this string you have the escape character after the ' and it should be before. Although, you appear to be using ASP for this so you shouldn't need it.
What I'd suggest doing is rewriting the string and using double quotes instead of single to the tag attributes. You can either write it like """ or you can use chr(34) ("foo" & chr(34) & " " & chr(34) & "bar").
Code:
Response.Write (' onclick=" & chr(34) & "javascriptpenWin(this.href, 1);return false;" & chr(34) & " Title=" & chr(34) & "Search for a Directory ID" & chr(34) & " onmouseover=" & chr(34) & "window.status='Search for a Directory ID'; return true" & chr(34) & " onmouseout=" & chr(34) & "window.status=''; return true" & chr(34) & ">Get ID </a>")
-
Oct 16th, 2002, 03:53 AM
#3
Thread Starter
Fanatic Member
Thanks Lee,
I've managed to get it to work in a very similar way to what you're suggesting, with the help of a couple of guys on the ASP forum within this site. I'd love to be able to claim I did it myself, however my conscience won't allow me to.
Code:
Response.Write("<a href='http://directory.com/startup.cgi")
If Len(Request.Cookies("txtUserID")) Then
Response.Write("?search_for=" & Request.Cookies("txtUserID"))
End If
Response.Write("' onmouseover=""window.status='Search for a Directory ID'; return true"" onmouseout=""window.status=''; return true"">Get ID </a>")
I've not actually tried your way, but will try it now.
Thanks for your help, until next time...
Oh I believe that the single quote is required as it closes off the href string.
Although I'm sure it would work without them, I just prefer to put them in.
Is that being purist? Probably not...!
Last edited by aconybeare; Oct 16th, 2002 at 03:59 AM.
-
Oct 16th, 2002, 08:42 AM
#4
Fanatic Member
No problem.
The way they suggested on the ASP forum will work the same way as chr(34).
And, you're right about the first ', I didn't notice it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|