473,387 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

libraries or functions to escape quotes, tabs, etc.

Hello,
I was wondering if there are any proper, robust libraries or
functions/methods that I don't know of that will escape all the
problematic characters such as single quotes and tabs. I find myself
writing
x = x.replace(/'/g,"\\'"); and the reverse over and over again.
Shouldn't Javascript have a built in method to do this? I know of the
escape() function but I am not sure if this is more for urls. What is
the real world way of storing such an "escaped" variable in a database
that will later be read into a javascript variable? :-/
Maybe one could use escape() and unescape() in some way, but some
expert probably could answer this in a snap.
Thanks!
Chris

Jan 5 '07 #1
1 1666
ch***************@gmail.com said the following on 1/5/2007 10:22 AM:
Hello,
I was wondering if there are any proper, robust libraries or
functions/methods that I don't know of that will escape all the
problematic characters such as single quotes and tabs. I find myself
writing
x = x.replace(/'/g,"\\'"); and the reverse over and over again.
Write a function that does it for you then:

function fixIt(x){
x = x.replace(/'/g,"\\'");
return x
}

myString = fixIt(myString)

And then you have your own library for it.
Shouldn't Javascript have a built in method to do this? I know of the
escape() function but I am not sure if this is more for urls. What is
the real world way of storing such an "escaped" variable in a database
that will later be read into a javascript variable? :-/
Having the server "fix it" before saving it and then sending it back to
the client.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 6 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: sinister | last post by:
The examples in the online manual all seem to use double quotes, e.g. at http://us3.php.net/preg_replace Why? (The behavior is different with single quotes, and presumably simpler to...
3
by: TheKeith | last post by:
Hi, I'm just learning php now for the first time and I'm having a little trouble understanding something. In the following example: ...
7
by: Leif B. Kristensen | last post by:
I'm working with a Python program to insert / update textual data into a PostgreSQL database. The text has single and double quotes in it, and I wonder: What is the easiest way to escape quotes in...
5
by: KathyB | last post by:
Hi, not sure this is the right group, but hoping someone may have experienced this. I'm passing html text as a parameter to a javascript. When it has an apostrophe in it, of course it does parse...
12
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" &...
7
by: Axel Dahmen | last post by:
Hi, within a DataGrid control I'm using a DataTable containing a string column to fill a Hyperlink's href attribute. Unfortunately HttpUtility.UrlEncode() doesn't escape the apostroph character,...
131
by: Lawrence D'Oliveiro | last post by:
The "escape" function in the "cgi" module escapes characters with special meanings in HTML. The ones that need escaping are '<', '&' and '"'. However, cgi.escape only escapes the quote character if...
0
by: gomzi | last post by:
hi, I would like to know as to what the equivalent functions are in .net for the escape and unescape functions that we have in javascript. tried both Server.HtmlEncode & Server.UrlEncode without...
10
by: Confused but working on it | last post by:
Hi all, I'm trying to do something simple and grabbed a snippet from the php manual for reading files in a directory. The snippet echos out a nice list of files. <?php //Open images directory...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.