|
| |
|
|
travismp
Posts: 274 Joined: 2/1/2002 From: hutchinson ks USA Status: offline
|
need help removing apostrophe in function - 10/14/2009 17:15:29
function LimitText(obj, numChars)
{
var temp = obj.value;
if(temp.length >= numChars)
{
alert("You must limit your input to " + numChars.toString() + " characters.");
temp = temp.substring(0,numChars-1);
}
obj.value = temp;
return;
}
I have an ASP page which saves data to a backend SQL DB. I have multiple text fields which will save on my page to the DB. I currently run this funtion the make sure the total characters are within a set number and all works perfect. I do have one issue thou, if I type in a sigle quote or an apostrophe and hit submit I get this error:
Microsoft OLE DB Provider for SQL Server error '80040e14'
Incorrect syntax near 's'.
So can I add anything to my function above that will simply replace any single quotes with nothing (remove the problem character) while it is checking for the character limit? Thanks.
|
|
|
|
womble
Posts: 6007 Joined: 3/14/2005 From: Living on the edge Status: offline
|
RE: need help removing apostrophe in function - 10/15/2009 6:18:55
Unfortunately ASP doesn't support escaping characters like PHP does (in PHP you can escape characters by preceding them with a backslash). You're getting the error because the server comes across the single quote or apostrophe and thinks it's the end of the string, so can't make sense of any commands following it. With ASP though you can use the chr() function to get characters (see the W3Schools site, where the ASCII code for the character goes between the brackets - you just need to get a list of ASCII codes to work out which codes you need to return different characters. It's ages since I've done anything in ASP (I only toyed with it briefly before deciding I liked PHP better) so I'm not sure of the right syntax to do it, but it should be fairly easy to write a conditional statement that says 'if you find a ' in a string, replace it with chr() '. There's a nice list of the ASCII characters here.
_____________________________
~~ "A cruel god ain't no god at all" ~~ ~~ Erase hate. Practice love. ~~
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|