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 = {     '&': '&amp;',     '<': '&lt;',     '>': '&gt;',     '"': '&quot;',     "'": '&#039;'   };    return text.replace(/[&<>"']/g, function(m) { return map[m]; }); } 

source: htmlspecialchars equivalent in javascript?


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -