How can I escape double quotes from a text input in javascript? -
in variable, string data coming text input following.
var notestr="<?php echo $_request["notestr"];?>";
if user given double quotes in text input javascript give error expected. not finding way use javascript str.replace() in scenario because before using on string variable javascript engine generate errors.
how can solve problem using javascript? advance help.
use php function htmlspecialchars().
var notestr="<?php echo htmlspecialchars($_request["notestr"]); ?>";
and here's javascript equivalent:
function escapehtml(text) { var map = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }; return text.replace(/[&<>"']/g, function(m) { return map[m]; }); }
Comments
Post a Comment