javascript - Remove apostrophe from a string -
javascript - Remove apostrophe from a string -
i working within programme allows me reference database fields using syntax such {cli:firstname}, references client's first name. programme allows me utilize html , java script display web page within window within program.
the problem having have written lot of pages , scripts display right information, have found problem. have scripts pass database field function such as
function a('{cli:firstname}'},'{cli:lastname}'){ logic; }
i pass way because function in external .js file. programme using not allow me reference database field straight except in .html file displaying in window in program. therefore, every function in .js has similar parameter list. can write function in header of page , straight access database field without passing field parameter, causes other problems, , moved scripts out due speed , other limits in programme displaying web page.
the problem occurs when seek pass database field has apostrophe in function in the.js file. crashes function call, since apostrophe string delimiter. of functions event driven, when page loads. order of operations programme database query first, , renders html next normal flow web pages. when, load page , field has apostrophe in it, , in function call, error message. illustration name: o’malley crash script. need prepare after database query complete, can go through fields utilize parameters in functions , escape apostrophe /’ before pass function.
my first thought write function on html page, hence can access database field straight , escape apostrophe, , pass value other functions. way apostrophe removal function generic plenty work other of fields apostrophes. need help on how write function , pass functions result function.
function removeapostrophe (){ var firstname = ‘{cli:firstname}’; // sets variable equal string in database // each field utilize parameter in other functions }
why not utilize double quotes instead of single quotes
javascript
Comments
Post a Comment