Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Clean a database record off an apostrophe '

by dws (Chancellor)
on Jul 29, 2002 at 19:36 UTC ( [id://186059]=note: print w/replies, xml ) Need Help??


in reply to Clean a database record off an apostrophe '

my problem is that it gives me a runtime error when ever my address record contains an apostrophe character (').

You're on the right track in thinking that you need to escape the single quote, but on the wrong track in thinking that you need to do this in the database.

It suffices to "escape" the single quotes right before you emit the Javascript. Try something like the following (untested, but I've done something like this before a few years back):

# after you've fetched the row my $escapedCustno = jsescape($custno); ... print <<EndHTML; <script language="javascript"> fillCustomer('$escapedCustno', ... sub jsescape { my $str = shift; $str =~ s/("')/\\$1/g; $str; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://186059]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-25 09:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found